I am facing small issuse with .htaccess and subdomain. To give some information, i am developing some project in php. And need to have url handled this way
My application user put their name as myname.domainname.com
they put myname.domainname.com then still i need to keep that url as it and need to call my internal file to process their data. example: i need to call myphpfile.php or any other file that i am using in application. so when any file is cal开发者_JS百科led from the url then i want to retrive subdomain name so that i will able to get related data
Let me know if somebody provide me simple solution. i have developed many files , now i got stucked to achieve the results.
Create a wildcard DNS entry for *.domainname.com
Create a wildcard virtual host for *.domainname.com
<VirtualHost *:80>
ServerName *.domainname.com
DocumentRoot /var/www/html
</VirtualHost>
All requests to all subdomains will go to the same document root, the same set of PHP scripts of yours.
$_SERVER['SERVER_NAME']
gives the whole host name (e.g. myname.domainname.com). If you only want the subdomain part, use:
$subdomain = preg_replace('#\..*$#', '', $_SERVER['SERVER_NAME']);
精彩评论