2012-03-22 47 views
2

我想改写这个网址:http://www.sample.com/product_guide&product_name=waht&product_type=dog-clipper
到:
http://www.sample.com/waht/dog-clipperhtaccess的URL重写 - 多个变量

我使用这个htaccess的代码:

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

但它不工作。请帮帮我。

+1

等待,您希望最终用户看到并使用哪个?通常情况下,这将是'http:// www.sample.com/waht/dog-clipper',并且您有向后重写。 – 2012-03-22 02:54:30

+0

我希望用户看到'http:// www.sample.com/waht/dog-clipper'而不是动态计数器部分。 – 2012-03-22 03:24:59

回答

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] 
+0

我无法得到它的工作。我正在使用这个htaccess测试器'http:// htaccess.madewithlove.be /' – 2012-03-22 03:39:10

+0

@jaysonatic它会工作 - htaccess测试器不能处理'REQUEST_FILENAME'条件。测试时将它们评论出来,它会正常工作,但在将其投入生产时将它们添加回来。 – 2012-03-22 13:39:30