Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting subdomains using htaccess

I want to set a subdomain for all site users, like www.companyname.mydomain.com I would like to use htaccess for this.

when somebody requests www.companyname.mydomain.com it should redirect to myfile.php?name=companyname

How can I achieve this using an htaccess file ?

Thanks for the consideration.

like image 715
milan Avatar asked Nov 14 '22 11:11

milan


1 Answers

Make sure this website is configured to respond to *.mydomain.com.

RewriteCond %{http_host}  ^www.(\w+).mydomain.com [NC]
RewriteRule ^.*$          /myfile.php?name=%1 [L]

You might want to adjust ^.*$, since this check will rewrite regardless of what comes after www.companyname.mydomain.com.

like image 55
Fabian Avatar answered Dec 06 '22 04:12

Fabian