So with some help I set this up a while back. It redirects/rewrites all index files to root and no www to www. I then found out that it was redirecting all my addon domains to www.maindomain.com/addondomain. I then added some fixes to it. BUT! Now if I don’t have a index in the addon domain it redirects to www.maindomain.com/addondomain again. Is this normal behavior for said code? Or is there something amiss with the code? I need this fixed because I dont want google thinking any addon domains are subdirectories of the main domain. Thanks!
I’ll be back after football but your addon domains should NEVER see the .htaccess in your main account’s root. It looked like you’re using their subdirectories in your .htaccess though, so main domain requests WILL be affected (but only via the main domain).
Not really sure what you mean. The us domain code currently in there prevents it from redirecting to main/addon regardless if index file is there or not.
Redirects all index files (on maindomain.com) to DocumentRoot’s index.html
Enforce www on maindomain.
There is no way that your .htaccess in the DocumentRoot of maindomain can ever be read for requests of any addondomain (so any reference to addondomain is … well, silly).
Since your addondomains ARE subdirectories of maindomain, you’ll need to add code to each addondomain to enforce their stand-alone status.
PLEASE wrap your code in [noparse]
...
[/noparse] tags as that preserves the code when quoting for a reply.
[COLOR="#0000FF"]RewriteEngine on
# Send subdomains off to their own domains so
# you don't need to worry about exclusions below
RewriteCond %{HTTP_HOST} ^((www\\.)?([a-z]+\\.))maindomain\\.com$ [NC]
# Capture optional www and subdomain (better to list your subdomains inside (sub1|sub2|...) )
RewriteRule .? http://%1com{%REQUEST_URI} [R=301,L]
# Send {REQUEST_URI} to subdomain.com
# Note, this can also send to www.maindomain.com
# (if you don't list as recommended above) but
# that will be corrected below[/COLOR]
# 301 permanent redirect index.html(htm) to folder [COLOR="#808080"]with exclusion for addon domains[/COLOR]
[COLOR="#0000FF"]# Rephrased: Strip subdirectories from any index.htm(l) request[/COLOR]
[COLOR="#FF0000"]# RewriteCond %{HTTP_HOST} !(addondomain\\.com|addondomain\\.com|addondomain\\.com|addondomain\\.com|addondomain\\.com)
# Irrelevant
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /([^/]+/)*index\\.html?\\ HTTP/
# {THE_REQUEST} is a terrible variable to use and you don't need to use the whole thing!
# In fact, you don't need to use it at all![/COLOR]
RewriteRule .+/index\\.html?$ http://www.maindomain.com/index.html [R=301,L]
# 301 permanent redirect non-www (non-canonical) to www [COLOR="#808080"]with exclusion for addon domains[/COLOR]
[COLOR="#FF0000"]RewriteCond %{HTTP_HOST} !(addondomain\\.com|addondomain\\.com|addondomain\\.com|addondomain\\.com|websitecodetutorials\\.com)
# Ditto the above[/COLOR]
RewriteCond %{HTTP_HOST} ^www\\. [NC]
RewriteRule .? http://www.maindomain.com${REQUEST_URI} [R=301,L]
Don’t forget to use the No Case flag when trying to match the {HTTP_HOST} variable.
Well, I was in a rush last time but was concerned about the optional www with a subdomain (which could also be www of the maindomain) but rushed your answer out to you anyway. My apologies for not taking sufficient time.
Specificity:
Enforce www on maindomain.
Redirect all index.htm(l) to DocumentRoot’s index.html
Yes, taking the subdomains out of the equation with the first block meant that you no longer had to deal with them; enforcing www meant you no longer had to use an external redirection to the DocumentRoot’s index.html file; and you didn’t need to use {THE_REQUEST} for something that a RewriteRule can do far easily (which you were already doing anyway).
Please note that only the last RewriteCond atoms can be used so the backreference to %3 was previously used to prevent the redirection from www.maindomain.com to www.com.