Forum Moderators: phranque
I have a dedicated server that currently has one sub-domain running off the main site. This subdomain works fine with the URL subdomain1.mysite.com. However, when I created a second subdomain (call it subdomain2.mysite.com) through the control panel interface and load this directory with a file it gets redirected to www.mysite.com/subdomain2.
Now the first subdomain has been around awhile and was around before I switched to the dedicated server. Also, it was around before I inserted the following code into .htaccess to redirect non-www domain entries:
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) [mysite.com...] [R=301,L]
The hosting company's tech people say the problem is with this code and that any subdomain will get redirected. But it is not the case with subdomain1.mysite.com which still works as set up!
So I'm a bit lost here - why would the existing subdomain continue to work but any new ones added will not work?
Ask your host to look into this.
Failing that, add a second RewriteCond just like the first one to your ruleset, but put the second subdomain name in it.
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^second_sub\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(www¦second_sub)\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Jim
But this now raises a couple more questions:
1. What's better, to run a sub-domain using separate .htaccess files or setting each sub-domain up as a separate account within my hosting environment?
2. Are there any problems (i.e., operationally, search engine spidering, etc.) associated with having an .htaccess file for each sub-domain? At this point I do not really need search engines to spider my sub-domains but that could change down the road.
mod_rewrite code in .htaccess is interpreted per HTTP request, while mod_rewrite code in httpd.conf is compiled on server restart and is thereafter directly-executable. Therefore, mod_rewrite code in httpd.conf executes much faster than equivalent code in .htaccess.
Jim