如何重定向.旧网址转换为新网址. [Laravel,htacces] [英] how to redirect. old url to new url. [Laravel, htacces]

查看:93
本文介绍了如何重定向.旧网址转换为新网址. [Laravel,htacces]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

how to redirect old url to new url.

旧网址:http://www.example.com/main.php?id=111

新网址:http://www.example.com/n/111

old url: http://www.example.com/main.php?id=111

new url: http://www.example.com/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('http://www.example.com/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('http://www.example.com/n/'.$id);
    }else{
        App::abort(404);
    }

})->where('all', '.*');

这篇关于如何重定向.旧网址转换为新网址. [Laravel,htacces]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆