Hello. A while back with lots of help I put together this code and added exclusion for my addon domains. These are not sub domains. But separate domains with their own folders sitting in the public_html (same as www prob). Without the exclusions all urls would redirect to the main domain. So all was/is good. But now I'm getting into the domain biz and need to host many domains. Each time I add a domain I have to go into the main sites htaccess and add it to the code for exclusion. It's a pain. Is there anyway to rewrite this code so it automatically does it so I don't have to enter each new domain?

So root ( / ) is were the maindomain is. And /addondomain is where the addon domains are.

Here, I simply targeted the ONE domain you were targeting and checking whether there was a www. subdomain before redirecting. I'm not sure what you were doing with ^(([^/]+/)/) index\.html?$ except to match every index.html file ... but why not all files (your attempt to only change index.html file subdomains to www doesn't make sense to me). Therefore, in my redirection, I simply redirected to the original URI. If you, indeed, only want to redirect index.html files, then ^(./)index\.html?$ and /$1index.html would be easier to understand.

Okay, that's what I was whining about above. If it works for every file, why separate out the index.htm(l) files and treat them differently? If you're simply trying to remove the DirectoryIndex file(s), do it that way (and force the server to find the file and serve it after it's been stripped from the URI?!?).

No prob I will explain. Maybe you can simplify it. Guys over at webmasterworld with like 30,000 posts and most in the server forum put that together. Based on that and the way they spoke I assumed they new what they were doing. But who knows?

What I'm doing is Canonicalization. Canonicalization is when you can get to a domain in like 10 different ways your site juice can be spread between them. So the first rule is stripping the index if present so all directs to folders. That's the one that probably redirects the addon domains. The second rule is making sure all links without www are redirected to the www version of the site.

The main site sits in the root obviously at /. And the addon domains at root/folder - so /addon. The host is Hostgator. Apparently that's not a common set up because most are confused by it.

If you know of cleaner way to accomplish this that doesnt redirect the addon domains to the root domain and does it automatically without me having to add each new addon to the list I'm all eager ears!

Neither of these hardcode any domain name, so it shouldn't matter whether you access your site through an addon domain.

Thanks Jeff. Here is what the other guy that provided the original code had to say about your code here. Unfortunately he offered no alternative.

"The index redirect is an affront to decent coding. NEVER use (.*) at the beginning or in the middle of a RegEx pattern. Without a RewriteCond testing THE_REQUEST, the rule will generate an infinite loop.

The www redirect is below optimimum. Specifically, it fails to redirect a number of non-canonical hostname requests (e.g. www.example.com:80 and others). "

Any validity to any of that? Or is he just talking out his ass? Since this has very direct influence on my seo. And since this is for my site that puts food on my table, I have to take this very seriously. And not just use the first thing given. I need to know its the best for what it's intended.

"The index redirect is an affront to decent coding. NEVER use (.*) at the beginning or in the middle of a RegEx pattern. Without a RewriteCond testing THE_REQUEST, the rule will generate an infinite loop.

Actually the use of (.*) is both standard practice and frequently used even in the Apache documentation itself. In fact, the authors of Apache use it in exactly the same way that this other guy says is "an affront to decent coding." I don't see any validity to his argument (there is no infinite loop), and I trust the Apache documentation a lot more than some random person.

EricWatson said:

The www redirect is below optimimum. Specifically, it fails to redirect a number of non-canonical hostname requests (e.g. www.example.com:80 and others). "

The goal of the second rewrite rule, so far as I know, was to add "www." to URLs that don't have it. His example URL does have it. So why should it be redirected?

Perhaps the "issue" he meant to highlight is the port? So, for example, maindomain.com:8080 would redirect to www.maindomain.com (without the port). And that's true. However, if you know that your site is running on port 80 -- as virtually every site is -- then you're safe to leave off the port. And once again, the Apache documentation backs me up on this. They show a port example, and they say it's only "for sites running on a port other than 80." I don't think that applies to you. In fact, that applies to almost no one.

So this will rewrite all index's to folder? And rewrite all no www to include www? And not include addon domains? So if I want the same on the addons then I am to use the same set of rules in its htaccess? Is that all correct??? Oh and will it also add a " / " to the end of .com? So .com/

You can search your Apache config for "Listen". That's where you can check what ports your server is configured to work on. Also, if your site domain when typed in the address bar doesn't use a port number at all, then you're on port 80.

By and large, yes. I say "by and large" because there is a difference in behavior between the two. Though, based on what you wanted to achieve, these may be good differences. For example, in your original rewrite rule, index.html would be stripped from your maindomain URLs, but not from your addondomain URLs. Whereas the new rewrite rule will strip index.html from the URL regardless of the domain. Ditto for the www. Your original rule would not add www to your addon domains, whereas the new rule will.

You can search your Apache config for "Listen". That's where you can check what ports your server is configured to work on. Also, if your site domain when typed in the address bar doesn't use a port number at all, then you're on port 80.

By and large, yes. I say "by and large" because there is a difference in behavior between the two. Though, based on what you wanted to achieve, these may be good differences. For example, in your original rewrite rule, index.html would be stripped from your maindomain URLs, but not from your addondomain URLs. Whereas the new rewrite rule will strip index.html from the URL regardless of the domain. Ditto for the www. Your original rule would not add www to your addon domains, where

All sounds good. Just two remaining questions for ya then!? Will this also add a slash at the end of the .com/ if none is present? And based on your description, then I need NOT to add this code to my addon domains htaccess as well then? Correct? Thanks.

And based on your description, then I need NOT to add this code to my addon domains htaccess as well then? Correct? Thanks.

Correct.

EricWatson said:

Will this also add a slash at the end of the .com/ if none is present?

No. I'm not even sure if it's possible to control this. The HTTP request will always send the slash. But whether that slash is shown in the address bar seems to depend on the browser. The latest versions of Firefox and Chrome appear to not show the slash, even if I explicitly type it in, while IE9 seems to always show the slash, even if I explicitly leave it off.

No. I'm not even sure if it's possible to control this. The HTTP request will always send the slash. But whether that slash is shown in the address bar seems to depend on the browser. The latest versions of Firefox and Chrome appear to not show the slash, even if I explicitly type it in, while IE9 seems to always show the slash, even if I explicitly leave it off.

The original code dos this. This is a must! See you can test with this link http://www.websitecodetutorials.com/. If you leave it off its rewritten in. Yes some browsers don't show it but if you copy the URL they will paste it as you have it written. Because with it off and on can be two dif URLs. A Canonicalization issue.

Just tested it on Firefox. No it's there! Copy it. And paste it. When pasted it is there. Firefox just doesn't show it. But it's there.

That's correct. It's always there. Some browsers show it, some don't. But your rewrite rules have no power to control whether it's shown or not. Nor does it represent a difference resource (and thus not a canonical issue). site.com and site.com/ represent the same resource, just like site.com and site.com:80 represent the same resource.

That's correct. It's always there. Some browsers show it, some don't. But your rewrite rules have no power to control whether it's shown or not. Nor does it represent a difference resource (and thus not a canonical issue). site.com and site.com/ represent the same resource, just like site.com and site.com:80 represent the same resource.