RewriteEngine ON
RewriteRule ^video$ video.php [L]
the above line works
example.com/video
is interpret as example.com/video.php
now I need example.com/video?id=5&s=lorem-ipsum
to interpret as example.com/video/5/lorem-ipsum
- and vice versa
RewriteCond %{THE_REQUEST} video?id=([^\s&] )&s=([^\s&] ) [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteRule ^([\w-] )/([\w-] )/?$ video?id=$1&s=$2 [L,QSA]
RewriteRule ^([\w-] )/([\w-] )/?$ video?/$1/$2 [L,QSA]
doesn't work - in both directions
pls help
CodePudding user response:
With your shown attempts, please try following .htaccess rules file. These rules are assuming you want to infernally rewrite to index.php you can change php file name in 2nd set of rules as per your requirement.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##External redirect Rules from here..
##Redirect 301 to example.com/video/5/lorem-ipsum from example.com/video?id=5&s=lorem-ipsum
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/(video)\?id=([^&]*)&s=(\S )\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
##Internal rewrite for example.com/video?id=5&s=lorem-ipsum
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^video/([^/]*)/(.*)/?$ index.php?id=$1&s=$2 [QSA,NC,L]