Forum Moderators: phranque

Message Too Old, No Replies

subdomain redirect

subdomain redirect

         

janet901

8:05 am on Jul 25, 2005 (gmt 0)

10+ Year Member



I want to redirect all requests sent to non-existing subdomains to a directory. For example I want [mysite.example.com...] to go to http://www.example.com/blog/mysite. I'm using the following code form a previous post:

RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* http://www.example.com/blog/%1 [R=301,L]

mod_rewrite is working for other requests on my server, but not for this. My host said the subdomain MUST be created. Without a valid subdomain it will not be able to resolve any DNS servers to resolve the webspace.

I want to get my own server with root access, would I be able to get around this?

jdMorgan

2:18 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> will not be able to resolve any DNS servers to resolve the webspace.

They're right. You'll need to edit your DNS zone file to add "A records" for the subdomains (or a wild-card "*"). This is how the client (browser or search robot) gets the IP address associated with your subdomains, and accesses your server. Without these entries, it's likely that all subdomains except for "www" won't resolve in DNS, and the client then has no idea where it needs to send TCP/IP packets to. If it can't get to your server (by IP address), then your code won't run, and the client will get a DNS resolution error (with the message depending on the browser).

So, it's a contradiction, but true: In order to support "non-existent" subdomains, you have to define them in DNS.

Ref: DNS Oversimplified [rscott.org]

Jim

janet901

2:36 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



Thanks, thats very helpful :)

jdMorgan

3:07 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... And I forgot my manners -- Welcome to WebmasterWorld!

Jim