How do I use mod_rewrite to change the path and filename of a URL
-
01-07-2019 - |
Question
I want to take the url: http://www.mydomain.com/signup-12345
And actually give them: http://www.mydomain.com/signup/?aff=12345
I have NO history with mod_rewrite, HELP!
Solution
Something that I found relatively hard to find out was how to do the reverse of what you are doing, whereby you need to find out the value of part of the query string.
So for example:
If you wanted to rewrite the Url: http://www.example.com/signup-old-script.asp?aff=12345
to: http://www.example.com/signup-new-script.php?affID=12345
you could use:
RewriteCond %{query_string}& ^aff=((.+&)|&)$
RewriteRule ^/signup-old-script.asp$ /signup-new-script.php?affID=%2 [L,R]
Notice the % sign in the rewrite rule instead of the $ sign.
I had to do this so I could support old flash maps in a new site that had links to ".cfm" files with an ID in the query string.
OTHER TIPS
Try this :
RewriteRule ^/signup-(\d+)/$ /signup/?aff=$1 [I]
As far i know,
flag causes the RewriteCond to be ignored. - for "Ignore case" - from IsapiRewrite
version 2