Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

redirecting directory index to the root for multiple subdomains



10:21 am on Jun 18, 2013 (gmt 0)


I have seen previous topics re. directing index.html to / , but must admit that I do find it a bit confusing, as there are so many suggestions. Some say add code to the .htaccess file, others to the system config (not sure exactly what that is). Anyway, here's my problem. I mistakenly linked about 12,000 pages as index.html and want to get rid of the problem permanently (I have corrected my links now), redirecting anything that is index.html to the directory before. Here are some examples:

http://www.example.com/index.html to:

http://www.example.com/europe/index.html to:

http://www.example.com/europe/england/index.html to:

http://www.example.com/europe/england/somerset/index.html to:

http://www.example.com/europe/england/somerset/bath/index.html to:

http://www.blog.example.com/index.html to:

There are lots of different folders to redirect, so I was hoping to do something simple to tackle every url that is /index.html. Is there something simple that I can do to achieve this, rather than adding a huge chunk of code? Your suggestions (and patience!) are much appreciated. :)

Many thanks,


[edited by: phranque at 11:13 am (utc) on Jun 18, 2013]
[edit reason] Please Use Example.com [webmasterworld.com] [/edit]


10:31 am on Jun 19, 2013 (gmt 0)

OK, noted. Someone earlier on the post told me to do that, but I will make sure I fix it, when we decide what to do. Thanks.


10:37 am on Jun 19, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

GET /index.html HTTP/1.1
Host: www.europe.example.com

HTTP/1.1 301 Moved Permanently
Location: http://www.example.com/countries/europe/
GET /countries/europe/ HTTP/1.1
Host: www.example.com

HTTP/1.1 301 Moved Permanently
Location: http://www.example.com/europe/countries/europe/
GET /europe/countries/europe/ HTTP/1.1
Host: www.example.com

HTTP/1.1 404 Not Found

something on your server is adding that path information to the url and your next task is to find out where that is occurring.
it is happening in one of the following places:
- a .htaccess file in your document root directory or a subdirectory
- a server configuration file
- your CMS or the script that is generating these responses

look for "countries" in those places and report your findings.

note that www.europe.example.com and other hostnames may be in a separate virtual host configuration (and therefore possibly resides in another document root directory) or could possibly be hosted on a separate server.


10:43 am on Jun 19, 2013 (gmt 0)

Thanks. There is nothing else in the .htaccess file and the pages are static. How do I check my server configuration file? Whereabouts would I find that exactly?


3:53 pm on Jun 19, 2013 (gmt 0)

I'm back. :) I had to reproduce the issue on my local machine in order to find a working solution.

The problem occurs because rewrite rules match against filesystem paths, not URL paths. That's why the filesystem path to your subdomains gets added. There are a couple ways we can solve this.

Option 1)

In each if your subdomains, create an htaccess with just this one line:

RewriteOptions Inherit

This way, the subdomain will still run all the same rewrite code, but it will do so from the context of its own directory, so there won't be any path prefix.

Option 2)

We could change the rewrite to match against the URI instead of the filesystem path. That means we'll have to do most of the heavy lifting in a rewrite condition.

RewriteCond %{REQUEST_URI} ^/(.+/)?index\.html?$
RewriteRule ^ /%1 [R=301,L]


4:07 pm on Jun 19, 2013 (gmt 0)

Thanks Dideved for going to so much trouble. That was SO kind of you.

I tried Option 2, in the main .htaccess file, and everything seems to work perfectly. How fantastic! Thanks again. I can't believe we've managed to find such an elegant solution. Wow. I'm so chuffed with that. Wow! :) :) :)


12:47 am on Jun 20, 2013 (gmt 0)

you are correct in your understanding and you support my point.
two 301s lose as much PR as following a link through two pages.
the lesson is to link internally to the canonical url and fix externally referred non-canonical requests in a single redirect.

Also, I want to say that I've re-examined Matt's words, and I think, phranque, that you're right and I'm wrong, and I'll definitely have to include this bit of information in the future.

Though, I think ease of maintenance is still a factor, and for the specific situation in this thread, I think that's the factor that should win out. The OP didn't specify how many subdomains he has, but it sounds like there's one for each region, country and city, such as europe, england, and bath. If we omit the hostname from the rewrite rule, then that one rule can work for every subdomain. But if instead we were to hardcode a hostname, then we may need to copy-paste that rewrite rule for each subdomain.


6:08 am on Jun 20, 2013 (gmt 0)

Thanks. It's quite a big site, about 10 years old). There's about 1,000 old subdomains now. We restructured the whole thing as the subdomains were being treated separately in so many ways (e.g. Google Plus), and we wanted an 'authority site' where there was a collection of 'pages' rather than 'subdomains'. The result so far has been better than I could have hoped for, so far!

Thanks again for everything. This was a neat solution.


7:27 am on Jun 20, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Change all Redirect directives to use RewriteRule.

Put the index rule before the non-www/www rule in each case.
This 38 message thread spans 2 pages: 38

Featured Threads

Hot Threads This Week

Hot Threads This Month