htaccess url rewrite - 多个变量

时间:2012-03-22 02:52:22

标签: .htaccess mod-rewrite

我正在尝试重写此网址:http://www.sample.com/product_guide&product_name=waht&product_type=dog-clipper
 于:
http://www.sample.com/waht/dog-clipper

我正在使用这个htaccess代码:

 RewriteCond %{QUERY_STRING} ^product_guide&product_name=(.*)&product_type=(.*)$  
 RewriteRule ^$ %1/%2? [R=301, L]

但它不起作用。请帮帮我。

1 个答案:

答案 0 :(得分:3)

如果您希望用户访问http://www.sample.com/waht/dog-clipper,则会向后重写。您需要匹配该URL并将其重写为相应的查询字符串:

RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Match the first two groups before / and send them to the query string
RewriteRule ^([^/]+)/([^/]+) product_guide?product_name=$1&product_type=$2 [L]