Reputation: 470
I want to redirect
mysite.com/vids.php?id=265s2g
to
mysite.com/watch?v=265s2g
I have tried
RewriteRule ^watch?v=(.*)$ vids.php?id=$1
But gives me a not found error. What is the correct way to do it ?
Upvotes: 1
Views: 184
Reputation: 1225
You can use the following rule to redirect
RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC]
RewriteRule ^vids.php(.*)$ watch?v=%1 [L,R,NC]
The above rule will redirect,
http://anysite.com/vids.php?id=265s2g
to
http://anysite.com/watch?v=265s2g
Try the test at http://htaccess.madewithlove.be/
Upvotes: 0
Reputation: 785186
You can't match query string in rewrite rule. Use it this way:
RewriteCond %{QUERY_STRING} ^v=([^&]+) [NC]
RewriteRule ^watch$ vids\.php?id=$1 [L,R,NC]
Upvotes: 1