Forum Moderators: phranque

Message Too Old, No Replies

Redirect subdomain to a folder - not working

         

flycast

1:07 pm on Dec 10, 2009 (gmt 0)

10+ Year Member



I have the following code that seems to work for others but not for me:

RewriteCond %{HTTP_HOST} ^sub.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.sub.example.com$
RewriteRule ^(.*)$ http://www.example.com/sub[R=301,L]

I get the message:

Firefox can't find the server at test.domain.com.

If I tweak this redirect like this it works fine:

RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://www.cnn.com[R=301,L]

I am thinking that there is something about my Apache config that is assuming that if the domain is test.domain.com then it must be a subdomain so it ignores the htaccess mod_rewrite code.

I have migrated servers and want to move subdomains to folders so that the domain ssl cert covers the area that was the subdomain. Hence, the need for the rewrite on certain subdomains. Does anybody have any ideas on this?

[edited by: jdMorgan at 2:37 pm (utc) on Dec. 10, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:38 pm on Dec 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The specific problem indicated by the Firefox error message is that you have not defined "test.example.com" in your DNS zone file; Firefox cannot retrieve the IP address to which your request should be sent. Therefore, it is the DNS lookup that is failing, and your test request isn't even reaching your server.

Jim

g1smd

8:52 pm on Dec 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't forget to escape the literal periods in the patterns in all of your conditions and rules too.

flycast

3:47 am on Dec 11, 2009 (gmt 0)

10+ Year Member



So for every subdomain that I want to redirect I will need a dns A record? I just looked and there are DNS records for some of the subdomains except the one I was testing (test.domain.com). I just added one.

I wonder if I can use a *.domain.com dns entry that will pick up all subdomains that are not specifically called out with their own DNS A record?

g1smd

9:35 am on Dec 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use a wildcard if you have dedicated hosting, and you will need to make absolutely sure how any and all such requests are handled. It is very easy to suddenly present Google with thousands of identical websites.

jdMorgan

3:23 pm on Dec 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dedicated hosting isn't required; only a dedicated IP address with "IP-based virtual hosting."

If it was possible for you to add the "test" subdomain and make it work with no other changes required to the server configuration (e.g. if you didn't have to "add" the test subdomain in Control Panel), then you've already got a dedicated IP address.

But do be careful to handle all of the "undefined" wild-card subdomains as g1smd says, either by 301-redirecting them to the main domain or to an 'error page' on a single domain/subdomain/hostname, or by returning a 403, 404, or 503 server response if an 'undefined' subdomain is requested.

Jim