Configuring subdomains using htaccess

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

when someone asks www.companyname.mydomain.com, should he redirect to myfile.php? name = Company Name

How can I achieve this using the htaccess file?

Thank you for the attention.

+5
source share
1 answer

Make sure the response to * .mydomain.com is configured on this website.

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

You might want to customize ^.*$, as this check will be overwritten regardless of what happens after www.companyname.mydomain.com.

+1
source

All Articles