Forum Moderators: phranque

Message Too Old, No Replies

subdomain redirect

is it possible to redirect wildcard subdomain?

         

belfasttim

9:49 pm on Jan 19, 2009 (gmt 0)

10+ Year Member



Hi all--

I've had some experience doing .htaccess redirects, but I've come across a question I haven't found a good answer for yet--

I can do a redirect from a subdomain to a page within the domain (eg. sub.mysite.com -> mysite.com/subpage.php) without issue.

But does every subdomain need an entry in DNS? or is it possible to set a "wildcard" A record (or something) in DNS, so every subdomain request for a given domain will go to the same page to be handled?

I was trying to do something like have every new user of the site get a subdomain to him/herself-- so if Joe signs up he'd have joe.mysite.com, though the content would be at mysite.com/page.php?id=joe. However, it's not feasible to have hundreds of DNS A records for every person that signs up.

Any ideas most appreciated.

jdMorgan

12:27 am on Jan 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DNS delivers a request for a domain name to the IP address of your server. As such, it is not aware of "pages," only domains.

You define wild-card DNS simply by prefixing your domain name with "*." as in "*.example.com."

Note the trailing period on the domain name, indicating a Fully-Qualified Domain Name (FQDN) required in a DNS "A" record.

Once the request arrives at your physical server, it is passed to your "software" server, e.g. Apache. If you have a dedicated server or an IP-address-based shared server, you can say that your server receives control at this point. However, if you are on a name-based server, then the shared "part" of the server must examine the "Host" header in the HTTP request to determine which virtual server to pass that request to. This step isn't needed on non-name-based servers, since in those cases, the IP address of your server fully-indicates its identity.

So, DNS is only the first step. After that, name-based shared virtual hosts will have to be configured to deliver the request into your account --your filespace-- where your .htaccess file can be applied.

We've discussed using mod_rewrite in .htaccess to map subdomains to subdirectories quite a bit here, so try a search of the Apache forum (see search link at top left of pages).

Jim

belfasttim

1:22 am on Jan 20, 2009 (gmt 0)

10+ Year Member



Thanks Jim--

I was hoping that was the answer, I figured you'd just enable a new virtual host entry in the apache sites-enabled for each subdomain, but it was going to be a pain to hassle with the DNS on each entry.

I hadn't considered how having a shared hosting setup would impact this scheme, so thanks for the tip.

Tim

belfasttim

12:38 am on Jan 21, 2009 (gmt 0)

10+ Year Member



I just wanted to post this thread here, since it was 90% of the solution to my situation:

[webmasterworld.com...]

Thanks for the help Jim