Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Whenever I type a made up address that includes a directory index it removes it. The problem is when the the address includes a forbidden subdirectory. It reduces itself until it hits forbidden. How do I get it to redirect to the homepage instead of reducing itself?

Options -Indexes +FollowSymlinks -MultiViews
RewriteEngine on

DirectoryIndex index.htm index.html index.php

# REDIRECT www to non-wwww
# Set Canonical URL
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# REMOVE Directory Index From URL
RewriteRule ^([a-zA-Z0-9_-]+/)?index\.(htm?|html?)$ /$1 [R=301,L]

# Custom Error Documents
ErrorDocument 404 /errors/404_notfound.htm
share|improve this question
I'm just a bit puzzled by your "forbidden subdirectory" statement. Is this forbidden as in 403-Forbidden (unauthorized)? IMO your RewriteRule would result in a redirect loop for any legitimate URL as well? – w3dk Jul 9 '13 at 22:52
Yes, it is 403 forbidden. I don't understand why the RewriteRule would result in a redirect loop for any legitimate URL. – user25687 Jul 10 '13 at 12:57
Are you saying then that it does not result in a redirect loop for legitmate URLs? It literally is only for 403 URLs? How are you serving/protecting your content - is this later in your server-side code? – w3dk Jul 10 '13 at 14:30
@w3d Sorry for the messed up formatting. That main problem is when it is rootdomain.com/forbidden403/madeupfakesubdirectory/madeupfake - it shows a 404 THEN reduces to rootdomain/madeupfakesubdirectory/index.htmlTHEN reduces to rootdomain.com/forbidden403. Shouldn't it redirect to a 404 page then redirect to the homepage ABSOLUTELY? – user25687 Jul 10 '13 at 15:15
@w3d No legitimate urls work just fine. For example:rootdomain.com - fine. rootdomain.com/foo - fine . rootdomain.com/madeupfakesubdirectory - 404 then redirects to rootdomain.com – user25687 Jul 10 '13 at 15:16

Your Answer


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

Browse other questions tagged or ask your own question.