I've got a problem to rewrite a URL. I want this:
http://www.example.net/test.php?u=s1&id=12345&img=12
to
http://app.example.net/12345-s1-12.test
The first parameter, u
, is a string. Parameters id
and img
are integers.
I've started with something like this:
RewriteCond %{REQUEST_URI} ^/test.php?u=(.*)&id=(.*)&img=(.*)/ [NC]
RewriteRule (.*) http://app.example.net/%2-%1-%3.test [QSA,R=301,L]
It still doesn't work, but I'm close!
RewriteCond %{REQUEST_URI} ^/test.php [NC]
RewriteCond %{QUERY_STRING} ^u=(.*)&id=(.*)&img=(.*)
RewriteRule (.*) http://app.example.net/%2-%1-%3.test [QSA,R=301,L]
Now it gives me this link:
http://app.example.net/12345-s1-12.test?u=s1&id=12345&img=12
Instead of:
http://app.example.net/12345-s1-12.test
:(
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.