RewriteRule不起作用

时间:2013-07-08 20:34:34

标签: apache .htaccess url mod-rewrite

我想转换此网址:

http://ts.thebenamorgroup.com/g2g/category.php?cate=mens

为:

http://ts.thebenamorgroup.com/g2g/category/cate/mens/   

我有这个规则,但它不起作用:

Options +FollowSymLinks
RewriteEngine on
RewriteRule category/cate/(.*)/ category.php?cate=$1
RewriteRule category/cate/(.*) category.php?cate=$1

2 个答案:

答案 0 :(得分:2)

你的重写是相反的方向。即重写

http://ts.thebenamorgroup.com/g2g/category/cate/mens/ 

为:

http://ts.thebenamorgroup.com/g2g/category.php?cate=mens

如果你想要的是重定向

http://ts.thebenamorgroup.com/g2g/category.php?cate=mens

为:

http://ts.thebenamorgroup.com/g2g/category/cate/mens/   

然后你可以使用: -

RewriteEngine on

RewriteBase /

RewriteCond %{QUERY_STRING} cate=(\d+) [NC]
RewriteRule ^g2g/category\.php$ /g2g/category/cate/%1/ [NC,R]

答案 1 :(得分:1)

尝试:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /g2g/

RewriteRule ^category/cate/(.+?)/?$ category.php?cate=$1 [L]

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /g2g/category\.php\?cate=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /g2g/category/cate/%2?%3 [L,R=301]