CakePHP将.php重定向到控制器

时间:2012-09-18 13:57:11

标签: .htaccess cakephp mod-rewrite

我的旧网站网址结构如下:

http://www.example.com/index.php?go=archives&data=lastweek

今天,我迁移到CakePHP,因此该URL无效。所以我想将其重定向到此网址:

http://www.example.com/archives/find?data=lastweek

(我不想将查询字符串更改为action参数,出于某种原因,我应该将其保留为查询字符串。)

我该怎么办? (编辑哪个.htaccess文件?CakePHP有3个文件!)

1 个答案:

答案 0 :(得分:0)

在文档根目录中的htaccess文件中(最好是可能已存在的任何规则),添加以下内容:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^go=archives&data=([^&]+)
RewriteRule ^/?index.php$ /archives/find/?data=%1 [L,R=301]

这应该将/index.php?go=archives&data=anything重定向到/archives/find?data=anything