: Cyclic redirection in .htaccess I have the following .htaccess file: AddDefaultCharset utf-8 RewriteEngine on Options +SymLinksIfOwnerMatch RewriteBase / # redirect all www-requests to no-www # - RewriteCond
I have the following .htaccess file:
AddDefaultCharset utf-8
RewriteEngine on
Options +SymLinksIfOwnerMatch
RewriteBase /
# redirect all www-requests to no-www
# -
RewriteCond %{HTTP_HOST} ^www.site.com$ [NC]
RewriteRule ^(.*)$ site.com/ [R=301,L]
# redirect all home pages to / (root)
# -
RewriteCond %{THE_REQUEST} ^.*/index.(php|html?)
RewriteRule ^(.*)index.(php|html?)$ / [R=301,L]
# remove trailing slash from dirs
# -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ / [R=301,L]
# automatically add index.php when needed
# -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond !^(index.php|login.php|reg.php|robots.txt|css/|js/)
RewriteRule ^(.*)$ /index.php [L]
The .htaccess file should do the following (for SEO):
Conversion to no-www (http://www.site.com should become site.com) All URIs with trailing slashes should convert to no-trailing-slash: site.com/me/ should be redirected site.com/me All URIs with index.php/index.html should convert to just nothing: site.com/admin/index.php or site.com/admin/ should be eventually displayed as site.com
However the current version of .htaccess results in a cyclic redirection when trying to access (http://site.com/admin). The real document that should be fetched by browser is site.com/admin/index.php.
Can anyone please help me with this issue?
More posts by @Heady270
1 Comments
Sorted by latest first Latest Oldest Best
I'm familiar with regex, though not an expert, but it looks like you might be getting a loop from the conditions under # redirect all home pages to / (root) and # automatically add index.php when needed
It looks like the last bit may be redirecting site.com/admin to site.com/admin/index.php, which tries to load and is then redirected back to site.com/admin by the earlier bit.
I think you don't need the last bit. Unless your server is configured improperly, site.com/admin should automatically fetch the document at site.com/admin/index.php
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.