Reputation: 3986
I have a multi-tenant site that spans across 3 different domain names. So for example:
client1.website.com
client2.website.net
client3.website.us
etc
In PHP I can use $_SERVER['HTTP_HOST']
to get the host name and determine if they are on website.com
, website.net
, etc.
I want to do the same in my .htaccess
file as I have a couple of rewrite conditions.
Here they are:
RewriteCond %{HTTP_HOST} ^regionapi\.website\.com
RewriteCond %{HTTP_HOST} !^website\.com$ [NC]
Can I do something like this?
domain = %{HTTP_HOST}
RewriteCond %{HTTP_HOST} ^regionapi\.{domain}
RewriteCond %{HTTP_HOST} !^{domain}$ [NC]
I might be way off but it would be great if this can work.
Upvotes: 1
Views: 629
Reputation: 47169
You should be able to do this by using something such as the following in your .htaccess
:
RewriteCond %{HTTP_HOST} (www\.)?regionapi\.example\.(com|net|us)$ [NC]
RewriteRule ^(.*)$ http://example.%2/$1 [R=301,L]
Depending on the domain name extension regionapi.example.(com,net,us)
would redirect to:
http://example.(com,net,us)
Upvotes: 1