Non hard-coded domain for subdomain exclusion.

New to mod_rewrite? This is a good place to start.

Non hard-coded domain for subdomain exclusion.

Postby Ulysses » Tue Sep 30, 2014 8:22 am

I have been using non-www to www RewriteRule for some time, but recently noticed that this breaks our subdomains. As we use a standard htaccess file for loads of subdomains on loads of domains, we really need a multi-site solution for excluding subdomains usign a RegEx style solution rather than hard-coding domains for all the htaccess files.

Hard-coded works:
Code: Select all
RewriteCond %{HTTP_HOST} !^([^.]+\.)domain.tld$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


But how do we get this to work without hard-coding the domain? I tried to use HTTP_HOST but that often returns the www which is not what we want. Also tried a script I found online that worked for domains with like .com and .net but not for .org.uk or co.uk etc.

Any help would be appreciated.
Ulysses
 
Posts: 10
Joined: Thu Sep 18, 2008 7:58 am

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 11 guests

cron