Most of my htaccess rules redirects unsigned users to index.html.
But when I redirect them to index.html, all of these rules are re-run for that page also. I need to run a minimum set of rules for the users visiting index file.
It’s obvious that [L] stops htaccess rules’ running.
What would be the better way for this issue? Is this a proper way to do it or do you have any better recommendations?
RewriteCond %{REQUEST_URI} index\.html
RewriteRule ^(.*)$ index.html [L]
My full htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} (\/onefolder|\/secondfolder) [NC]
RewriteCond %{REMOTE_ADDR} !111\.22\.33\.44 [NC]
RewriteCond %{REQUEST_URI} !(index\.html) [NC]
RewriteRule ^(.*)$ index.html [F]
RewriteCond %{HTTP_USER_AGENT} oneagent|otheragent [NC]
RewriteCond %{REQUEST_URI} !(index\.html) [NC]
RewriteRule ^(.*)$ index.html? [R=301,L]
RewriteCond %{HTTP_USER_AGENT} betteragent|otherbetterganet [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(index\.html) [NC]
RewriteRule ^(.*)$ index.html? [R=301,L]
RewriteCond %{HTTP_COOKIE} !username [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\/importantone|\/somefolder|index\.html) [NC]
RewriteRule ^(.*)$ index.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
A few things you can do. If you want to simply stop rewriting for
index.html, you can do something similar to what you have (but simpler), at the very top of your rules:The
-is simply to “pass through”, essentially making it so rewriting stops there.Alternatively, you can prevent looping completely by adding this to the top of your rules:
Does something similar but checks if there was an internal redirect of any kind.