Forum Moderators: phranque

Message Too Old, No Replies

One Subdomain Works, Another Doesn't

         

PaulPA

1:14 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



This one has me a little stumped:

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?

jdMorgan

2:43 pm on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the first subdomain set up as a different VirtualHost? If so, it will never run your main-domain .htaccess code, and therefore won't be affected by the domain rewrite. If, however, the second subdomain simply defaults to the same VirtualHost as the main domain, then it would be subject to the rewrite, and will be redirected to the main domain.

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]

or equivalently:

RewriteCond %{HTTP_HOST} !^(www¦second_sub)\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

You'll have much simpler rules, though, if you get your host to set up the second subdomain with its own separate filespace, just like the first subdomain.

Jim

PaulPA

4:36 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Jim - Thanks. I'll look into this.

PaulPA

1:01 pm on Mar 17, 2006 (gmt 0)

10+ Year Member



It looks like the issue may have been with the .htaccess file, and more specifically, whether a .htaccess file also resides in the sub-domain. According to my host's tech support, a .htaccess file located in a sub-domain will override the top-level .htaccess. For the sub-domain that did work for me there was another .htaccess file (I used this sub-domain as a testing area for my site which as a CMS that needs .htaccess) while the new sub-domain did not have a .htaccess file.

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.

jdMorgan

7:58 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It all depends on how 'separate' you want the sites to be. If they are truly separate sites, then you'll get better performance by defining each one in its own filespace, rather than using .htaccess to sort them out by requested hostname.

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

PaulPA

9:09 pm on Mar 17, 2006 (gmt 0)

10+ Year Member



Thanks for your help.