Web Hosting Talk







View Full Version : Wildcard Sub Domains


aixagent
09-08-2004, 08:37 PM
Anyone know how I can setup one of my domains so that, if someone does:

<somethinghere>.mydomain.com

It automatically does: www.mydomain.com/file.php?var=<somethinghere>

TIA.

Running apache if that information is necessary.

earthstar
09-08-2004, 11:42 PM
On Apache, are you running cPanel based hosting or other?

aixagent
09-08-2004, 11:51 PM
cPanel host.

I just need it for one of my domains.

lwknet
09-09-2004, 07:16 AM
you need to be root (WHM) to modify dns records
* in a 1.2.3.4

and httpd.conf in /usr/local/apache/conf
*.domain.com

then make a .htaccess in your /home/user/public_html to mod_rewrite the address

dawhb
09-09-2004, 09:23 AM
The above would set it up for the DNS part, you should however also set-up the Apache hosts for all the subdomains.
You can work-round this by putting some php into the default index for this IP. It will read the HTTP request headers and will forward to the desired addres so long as they call for something.yourdomain.com

lwknet
09-10-2004, 05:54 AM
you dont need to setup each subdomain in apache, apache takes *.domain.com in vhost setup

wheimeng
09-10-2004, 08:00 AM
That would point to the same site, if you need each subdomain to have their own page, then you would need to add virtualhost for each site.

Kamejoko
09-10-2004, 08:18 AM
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule ^.*$ /file.php?var=%1 [R,QSA]

This is redirect, however. I haven't figure out how to use internal redirection with this (ie the address bar should still be the sub.domain.com). Tried many ways but got 500 all the time.

Sheps
09-10-2004, 11:34 AM
Actually, if you set it to point at the same site, you could use the "hostname" server variable to get the current site it is visiting and then just pop that into a array. Very simple and very fast. No mod_rewrite or anything