GET请求htaccess重定向

时间:2014-04-21 11:40:10

标签: regex apache .htaccess mod-rewrite redirect

我需要从

重定向网址

website.com/search.php?city=india&keyword=laptop

website.com/search/india/laptop

如何使用htaccess执行此操作

在我的htaccess

中显示代码
Options +FollowSymLinks

RewriteEngine on

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ search.php?city=$1&keyword=$2

1 个答案:

答案 0 :(得分:0)

您可以在根.htaccess文件中使用此规则:

Options +FollowSymLinks -MultiViews

RewriteEngine on

RewriteCond %{THE_REQUEST} \s/+search\.php\?city=([^&]+)&keyword=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=301,L,NE]

RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?city=$1&keyword=$2 [L,QSA]