Hello I am trying to rewrite my url
http://example.net/?r=123
to this one
http://example.net/ref/123
In my .htaccess this is working using this code
RewriteEngine on
RewriteRule ^ref/([^/.]+)/?$ /index.php?r=$1 [R=301]
But i would like to add another rewrite rule. When the link is like this:
http://example.net/?r=123
I would like to redirect it to:
http://example.net/
I tried this rewrite rule but it's not working:
RedirectMatch "^/?r=([^/.]+)" "/index.php"
Please help. Any help will be very much appreciated. Thank you so much.
Try these rules to redirect the query string URL to the pretty URL which is more common. Basically redirecting the old url to the SEO friendly one.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /+\?r=([^&\s]+)\
RewriteRule ^ /ref/%1? [R=302,L]
RewriteRule ^ref/([^/.]+)/?$ /index.php?r=$1 [R=301]
If you still want to redirect the query string to index.php instead try this rule
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /+\?r=([^&\s]+)\
RewriteRule ^ /index.php [R=302,L]
RewriteRule ^ref/([^/.]+)/?$ /index.php?r=$1 [R=301]