2011-08-29 68 views
13

我有一个问题,重写一个URL。 我想这一点:RewriteCond带参数的网址

http://www.foo.com/test.php?u=s1&id=12345&img=12 

http://app.foo.com/12345-s1-12.test 

第一个参数u是一个字符串,参数id和IMG是整数。

我已经开始用类似的东西:

RewriteCond %{REQUEST_URI} ^/test.php?u=(.*)&id=(.*)&img=(.*)/ [NC] 
RewriteRule (.*) http://app.foo.com/%2-%1-%3.test [QSA,R=301,L] 

谢谢:)

编辑:

还不行,但我接近!

RewriteCond %{REQUEST_URI} ^/test.php [NC] 
RewriteCond %{QUERY_STRING} ^u=(.*)&id=(.*)&img=(.*) 
RewriteRule (.*) http://app.foo.com/%2-%1-%3.test [QSA,R=301,L] 

现在,它给我的链接:

http://app.foo.com/12345-s1-12.test?u=s1&id=12345&img=12 

相反的:

http://app.foo.com/12345-s1-12.test 

:(

回答

26

解决

RewriteCond %{REQUEST_URI} ^/test.php [NC] 
RewriteCond %{QUERY_STRING} ^u=(.*)&id=(.*)&img=(.*) 
RewriteRule (.*) http://app.foo.com/%2-%1-%3.test? [R=301,L] 

在RewriteRule的末尾放置一个?可删除以前的查询字符串信息。

-1

这完美的作品!我用这个 - 但我想知道为什么目标网址在最后显示“%3f”。

我使用:

RewriteCond %{REQUEST_URI} ^/ie/xx/yy.php [NC] 
    RewriteCond %{QUERY_STRING} ^rubric=(.*)&nr=(.*) 
    RewriteRule (.*) https://www.newdom.com/xx/yy.php?rubric=%1&nr=%2 [R=301,L] 

为什么在最后%3F?