I have my php site set up so the urls appear as .html but rewrite to .php behind the scenes. But, what I want it also to do is if someone does manually type in the urls with .php that they redirect/rewrite as html. So in other words, the .php pages are never displayed as .php under any circumstances. So mydomain.com/page.php manually entered would be redirected/rewritten as mydomain.com/page.html The code I currently use in my htaccess is: RewriteRule ^(.*)\.html$ $1.php [NC] Code (markup): Which works fine to rewrite all the .html urls internally to .php but doesn't prevent people manually entering .php urls which I don't want. I hope you get what I mean. Thanks in advance.
<Files ~ "^\.php"> Order allow,deny Deny from all </Files> Code (markup): I think that'll do it. Just put it in your .htaccess file.
Won't that just prevent them from accessing the .php urls completely? I want them to redirect to the .html versions of the pages not just block anyone.
It would prevent them from accessing it completely. You might be able to create some sort of weird Redirect using mod_rewrite. I am just not sure how well that would work out or how you'd do it without creating loops. It might be something like this: RewriteRule ^(.*)\.php$ http://yourdomain.com/$1.html [R=301,L] Code (markup): You'd probably have to put it above the .html one. I haven't tested it myself but this should point you in the right direction.
That wouldn't work 'cos I'd have to change the url for every page. I just want to redirect every .php page to the .html equivalent. I guess no-one knows how to do it.
OK, here is the solution for you RewriteRule ^(.*)\.html$ $1\.php [E=FLAG1:1,L] RewriteCond %{ENV:REDIRECT_FLAG1} !1 RewriteRule ^(.*)\.php$ $1\.html [R=301]
Dimma that's almost it but it doesn't quite work. If I try to query domain.com/page.php it redirects to domain.com/home/domain/public_html/page.html which obviously doesn't work. Update: You put me on the right track, Dimma and I managed to find the solution. For anyone wondering its: RewriteRule ^(.*)\.html$ $1.php [NC] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.?]+\.php rewriterule ^([^.]+)\.php$ http://www.domain.com/$1.html [R=301,L]