RewriteCond for url with parameters

老子叫甜甜 提交于 2019-12-20 09:37:44

问题


I've got a problem to rewrite an url. I want this :

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

to

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

First parameter u is a string, parameters id and img are integers.

I've started with something like that :

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

Thanks :)

EDIT :

Still doesn't work but i'm close!

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]

Now it give me that link :

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

Instead of :

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

:(


回答1:


Solved!

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

Placing a ? on the end of the RewriteRule removes previous query string information.




回答2:


This works perfectly! I used this - but i'm wondering why the target url shows "%3f" at the end.

I'm using:

   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]

Why is %3f at the end?



来源:https://stackoverflow.com/questions/7234005/rewritecond-for-url-with-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!