Eric,
Specification:
1. Redirects all index files (on maindomain.com) to DocumentRoot's index.html
2. 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 [code]...[/code] tags as that preserves the code when quoting for a reply.
Code:
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
# 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
# Rephrased: Strip subdirectories from any index.htm(l) request
# 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!
RewriteRule .+/index\.html?$ http://www.maindomain.com/index.html [R=301,L]
# 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|websitecodetutorials\.com)
# Ditto the above
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.
Questions? Problems?
Regards,
DK
Bookmarks