Reputation: 13822
Consider the following rules
RewriteRule ^index\.html$ index.php [L]
RewriteRule ^index\.php$ index.html [R=301]
I want .html
to use the .php
file, but I want the url to have the .html
extension always.
The above rule creates a redirection loop. What's the right way to do this?
Upvotes: 1
Views: 138
Reputation: 143966
You can either check against the actual request, or prevent looping entirely.
Option 1, check against request:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ index.html [R=301]
This makes it so if the actual request isn't index.php
, the redirect won't happen.
Option 2, prevent rewrite engine from looping entirely. Add this to the top of your htaccess file:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
The downside with this is that you may have rules that actually want to loop.
Upvotes: 1