坚持使用变量php重定向301

时间:2012-08-20 16:22:07

标签: php .htaccess

我正在尝试在.htaccess文件中写入301,但无法使其正常工作。我们的网址如下......

http://www.example.com/?cat=tree-category

http://www.example.com/?cat=food-category

我们想将这些更改为

http://www.example.com/directory/listings/tree-category

http://www.example.com/directory/listings/food-category

任何人都可以帮忙,非常感谢!

詹姆斯

1 个答案:

答案 0 :(得分:1)

这应该这样做:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^cat=([a-zA-Z0-9\-]*)$
RewriteRule ^(.*)$ http://www.example.com/directory/listings/%1 [R=301,L]

退房:http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/