GET方法的.htaccess路由问题



我的页面上有一个搜索引擎,它以get方法开头。搜索部分运行良好,但路由不行。我认为,我的.htaccess文件中会有问题,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET.*index.php [NC]
RewriteRule (.*?)index.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTP_HOST} !^www.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

因此,当我单击搜索按钮时,它会将我重定向到www.mysite.com/search?keyword=something.如果我从 URL 替换它以www.mysite.com/search/something引擎工作。所以我只需要从 .htaccess 重定向它。 你需要知道的是,我是用Codeigniter写的,路由部分是:

$route['/search/(:any)'] = "home/search/$2";

知道吗?谢谢你的帮助。

使用 php 重定向 修改您的 Routes.php 文件

$route['/search/(:any)'] = "home/search/$2";
$route['search']['get'] = function ()
{
$url='home/search/'.$_GET['keyword'];
header("Location: $url");
die();
}; 

最新更新