Forum Moderators: coopster
First of all, I'm very thankful for your great site .
I have a question.
I would like to create a virtual subdomain with PHP (I think I should do this with mod_rewrite and .htaccess)
for example :
[img54.img.mysite.com...] > [img.mysite.com...]
(the 54 is a variable and img.mysite.com is really a subdomain)
Now , what I should do?
P.S: sorry for my English :(
I am not thinking that is quite possible, variable subdomains, though I am not sure.
I believe if it was possible that it would be an Apache question more so than a php one.
You could try our Apache Forum [webmasterworld.com]
you can't "create" subdomains with PHP, but you could use them in PHP if your server setup lets you do so.
First, your DNS definitions for your domain name have to include a *.img.example.com. wildcard A record, so that all subdomains are mapped to your one server's IP address.
'Img54' is just one subdomain, 'img55' is another one. You need the * to catch them all.
Then, in your web server's configurations file httpd.conf, within your virtual host definition for img.example.com you have to specify a * wildcard alias, so that every possible subdomained host name points to the same document root of img.example.com.
Now you are ready to catch the subdomains within PHP
$subdomain = explode(".",$HTTP_HOST);
and do whatever you want with it, perhaps redirecting like the following simple example:
if(is_dir("$YOUR_DOCUMENT_ROOT/$subdomain[0]")) {
header("Location:http://img.example.com/$subdomain[0]");
} else {
header("Location:http://img.example.com/$somewhereelse");
}
Regards,
R.