如何重定向.旧网址转换为新网址. [Laravel,htacces]

编程入门 行业动态 更新时间:2024-10-26 22:20:05
本文介绍了如何重定向.旧网址转换为新网址. [Laravel,htacces]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将旧网址重定向到新网址.

how to redirect old url to new url.

旧网址:www.example/main.php?id=111 新网址:www.example/n/111 old url: www.example/main.php?id=111 new url: www.example/n/111

我的解决方案是:在routes.php中

my solution is: in routes.php

Route::get('/main.php?id={id}', array('uses' => 'App\Controllers\Front\PageController@oldToNew'));

实际情况:

public function oldToNew($id) { return Redirect::to('www.example/n/'.$id); }

,但是此代码无效.请帮忙.

but this code wont work. pls help.

推荐答案

您可以创建一条路由,以捕获不在route.php中的所有路由.它必须在您的routes.php文件的底部.

You could make a route that catches all routes that are not in your routes.php. It has to be in the bottom of your routes.php file.

在这里您可以检查id是否存在以及uri是否包含main.php.

Here you can check if id exists and if the uri contains main.php.

Route::get('{uri}', function($uri) { $id = Input::get('id'); if(preg_match('/main.php/i', $uri) && isset($id)){ return Redirect::to('www.example/n/'.$id); }else{ App::abort(404); } })->where('all', '.*');

更多推荐

如何重定向.旧网址转换为新网址. [Laravel,htacces]

本文发布于:2023-10-31 18:31:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   重定向   网址   新网址   htacces

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!