Hi Jim!
Okay, I guessed at that but it was still a very nice thing to see (the [ noparse ] wrapper). Not many are aware of that so maybe more will pick-up on this (as well as the [ code ] wrapper which many still won't use).
There shouldn't be any harm in posting your domain but I'll alter those in case one of the mods wants you to go incognito.
There are a number of tasks you need to handle which depend on the request being made:
1. Strip www from maindomain.net.
2. Redirect subdomain.maindomain.net to subdomain.com (retain the path/to/file? Yes, that would be kinder to your clients' visitors).
3. Handle CMS redirections within the subdomains.
If you handle task #1 first (the way you were doing it), you'll be stripping the subdomain information and will not be able to redirect to any subdomain.com.
Of course, you could match www\.maindomain\.net [NC] and redirect that to maindomain.net but you had chosen to strip them all. Pedantically, I addressed your code's introduced problem.
Task 3 should be handled within each subdomain's ({DOCUMENT_ROOT}) directory so that won't be handled by maindomain.net's .htaccess.
Therefore:
Code:
Options +FollowSymLinks
# You shouldn't need this as it should be in the server's conf file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^1foot\.enterprisejm\.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.enterprisejm\.net/1foot$
RewriteRule ^(1foot/)?([a-z.]*)$ http://1footinthegrave.com/$2 [R=301,L]
1. Don't forget to escape your dot characters to match just a dot character.
2. Don't forget that the domain name is NOT case sensitive but your regex matches are
... unless you use the No Case flag.
3. IF the 1foot subdirectory was requested, you do NOT want (.*) to match that,
too because it would be loopy. Using an optional 1foot/ should resolve that problem.
4. You are correct, I was being lazy (and wanted to capture everything in the {REQUEST_URI})
but it's a lot safer to correctly identify that you only want lowercase letters and dot characters
(you may want to add a / within the [...] brackets if your requests go deeper into the file structure)
and the * is correct as there may not have been a directory or file requested.
RewriteCond %{HTTP_HOST} ^linomaster.enterprisejm.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.enterprisejm.net/linomaster$
RewriteRule ^(.*)$ http://www.linomaster.com/$1 [R=301,L]
Ditto all the above comments on this block.
# more of the same for each domain
RewriteCond %{HTTP_HOST} !^enterprisejm\.net$ [NC]
RewriteRule .? http://enterprisejm.net%{REQUEST_URI} [R=301,L]
Right! NOW it's time to strip any remaining subdomain from maindomain.net! Of course, all that should be left at this point is the www subdomain (or subdomains which don't exist).
This is the htaccess in the public_html/1foot folder:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^1footinthegrave\.com$ [NC]
# You escaped this one AND used the No Case Flag! What happened above?
RewriteRule ^(.*)$ http://1footinthegrave.com/$1 [R=301,L]
# You duplicated the {REQUEST_URI} variable with $1. Why bother?
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? /index.php [L]
# The WP people will catch on some day but you can account for the domain-only
# request with the ?. Yeah, yeah, the DirectoryIndex should give index.php anyway
# but ... what if you've used default.php or default.asp instead?
# END WordPress
Ditto for the rest of your Addon Domains (cPanel's name for domains which are also subdomains of the maindomain within your account).
I hope I addressed the difference between the (.*) and ([a-z./]+) above. The real disadvantage to the (.*) is that newbies to regex will use it as a crutch to match whatever they want to match without recognizing the potential for loopy code. When someone comes here complaining that their code doesn't work (or loops), I look first for the (.*) everytime! Using specific characters or lists, e.g., (first|second|third), is a better way as the variable MUST match not any ridiculous string of letters but EXACTLY first OR second OR third. It makes for a good security check, too!
I hope that cleared away some of the confusion I introduced (with apologies, too).
Regards,
DK
Bookmarks