将URL重定向到代码点火器中的另一个URL


Redirect the URL to another, in codeigniter

我有一个用core php构建的网页,现在它已更新为codeigniter mvc。我面临的问题是,用户试图输入旧的URL路径

示例:www.website_name/old_path

现在,由于采用了mvc布局,它将无法工作,并将出现404错误。我想将进入www.website_name/old_path的客户重定向到新的

www.website_name/index.php/new_controller/new_view.

任何人都请帮我解决这个问题。

谢谢!

首先删除index.php配置文件。打开config.php并执行以下操作以替换

$config['index_page'] = "index.php"

$config['index_page'] = ""

然后在应用程序/文件夹中创建HTACCESS文件

有这个代码。。。。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

现在,index.php已从您的URl。。。。

步骤2)打开application/config/routes.php文件现在在这里定义您想要的网页URL

$route['mycontroller/(:any)'] = "mycontroller/user_detail/$1";

因此,您的URL将是。。www.website_name/new_controller(或xyz)/

在这里,您还可以使用路由以不同的方式更改控制器名称,因此没有人可以获得控制器/方法名称的确切名称。。。。要进行此类自定义,请参阅此URLhttp://www.codeigniter.com/user_guide/general/urls.html

正如Sumit所提到的,您应该为此使用URL路由。

在路由文件中,你可以创建一个你想要的所有重定向的列表,如下所示:

$route['old_path'] = "new_controller/new_view";

对于这种类型的问题,可以使用301重定向。

将此代码放入.htaccess

RewriteRule ^www.website_name/old_path www.website_name/index.php/new_controller/new_view [L,R=301]

或使用301重定向密码http://www.codeigniter.com/user_guide/helpers/url_helper.html

// with 301 redirect
redirect('/article/13', 'location', 301);