Forum Moderators: bakedjake

Message Too Old, No Replies

Question about subdomains

How to redirect for wildcard subdomains?

         

craig1972

1:02 am on Jun 26, 2003 (gmt 0)

10+ Year Member



Hi,

I have a script for extranet access that is like this:
[mydomain.com...]

I want to set up a rewrite rule that will allow
[<clientName>.mydomain.com...]

to be pointed to the above path automatically.

How can I set this up?

Thanks!

bakedjake

4:31 pm on Jun 26, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month




RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.mydomain\.com(.*) http://mydomain.com/cgi-bin/clients.pl?clientName=$1 [R,L]


... should work. I didn't test it, so it's off the top of my head. Let me know.

BTW - Use PT instead of R in the parameters if you want it to be transparent.

<Edited: Typo>

craig1972

10:54 pm on Jun 26, 2003 (gmt 0)

10+ Year Member



Thanks bakedjake, but this gives me a DNS error. Says domain xxxx.mydomain.com is not found. What am I missing? Thanks!

bakedjake

12:46 am on Jun 27, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You have to add xxxxx.mydomain.com to your DNS? :)

craig1972

1:11 am on Jun 27, 2003 (gmt 0)

10+ Year Member



But surely I cannot add all the variables to my DNS! Is it possible to have this without any DNS hassles? Alternatively, can I add it to DNS in my htaccess files because I am on a shared server?

Thank you.

bakedjake

1:24 am on Jun 27, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If your DNS server supports wildcards, you can do it that way. My DNS server (djbdns) does. But that part is done in the DNS server. When a client requests a DNS name, the DNS server will have to know which IP address to point them to.

Tell them that you need a wildcard DNS entry that points *.mydomain.com to your IP address. It should be a simple one-line addition to their DNS configuration.

Then use the rewrite formula above - it will sort out the header name and send them to the right place.

If they won't add it for you, find a webhost that will.