Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 ^(.*)$$1 [R=301,L]

# redirect all home pages to / (root)
# -
RewriteCond %{THE_REQUEST} ^.*/index\.(php|html?)
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,L] 

# remove trailing slash from dirs
# -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ /$1 [R=301,L]

# automatically add index.php when needed
# -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|login\.php|reg\.php|robots\.txt|css/|js/)
RewriteRule ^(.*)$ /index.php [L]

The .htaccess file should do the following (for SEO):

  1. Conversion to no-www ( should become
  2. All URIs with trailing slashes should convert to no-trailing-slash: should be redirected
  3. All URIs with index.php/index.html should convert to just nothing: or should be eventually displayed as

However the current version of .htaccess results in a cyclic redirection when trying to access ( The real document that should be fetched by browser is

Can anyone please help me with this issue?

share|improve this question

1 Answer 1

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 to, which tries to load and is then redirected back to by the earlier bit.

I think you don't need the last bit. Unless your server is configured improperly, should automatically fetch the document at

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.