Forum Moderators: phranque
Options +FollowSymlinks
RewriteEngine On
#if file extension is .do, process as .php page on server
RewriteRule ^(.*)\.do$ $1.php [nc]
#if file extension is .php, redirect to .do url
RewriteRule ^(.*)\.php$ $1.do [R=301,L]
The first bit by itself works fine, if you enter blah/blah.do?id=2, server will execute blah/blah.php?id=2
However if I add the second rule (to redirect .php requests to .do urls) it all breaks down.
I've been struggling with this for a few hours and my brain is starting to melt down. Any help would be appreciated, thank you!
# if requested file extension is .do, rewrite to .php file on server
RewriteRule ^(.*)\.do$ $1.php [L]
#
# if file extension .php is directly-requested by client, redirect to .do url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(.*)\.php$ $1.do [R=301,L]
Jim
Thank you very much, it worked a treat! In order to "learn how to fish" I'll be spending some time studying the example you gave.
I see on the first line you added the [L] parameter, which I think means that should be the last rule if true.
And the new RewriteCond, does that check to make sure that the client requested it and not a server redirect?
Anyway thanks again!