Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite subdomain

         

tuarek

11:23 am on Jun 17, 2010 (gmt 0)

10+ Year Member



I have a domain any.com with "wildcard".


RewriteEngine on
RewriteCond %{REQUEST_URI} !subdomains
RewriteCond %{HTTP_HOST} ^(www\.)?(.*).example.com$
RewriteRule .* /subdomains/%2%{REQUEST_URI}



But i need delegate two sub-domain (a.example.com, b.example.com) to the other server - new dns
how and what I do
please help

[edited by: jdMorgan at 3:02 pm (utc) on Jun 17, 2010]
[edit reason] example.com [/edit]

jdMorgan

3:00 pm on Jun 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In DNS, define A records for the two specific subdomains to point them to the 'other server.'

You code has one fatal error, and is prone to several other failures. I'd recommend:

RewriteEngine on
#
RewriteCond %{REQUEST_URI} !/subdomains/
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+(\.[^.]+)*)\.example\.com\.?(:[0-9]+)?$
RewriteRule .* /subdomains/%2%{REQUEST_URI} [L]

You could also write it as:

RewriteEngine on
#
RewriteCond $1 !subdomains/
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+(\.[^.]+)*)\.example\.com\.?(:[0-9]+)?$
RewriteRule ^(.*)$ /subdomains/%2$1 [L]

-or-

RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+(\.[^.]+)*)\.example\.com\.?(:[0-9]+)?$
RewriteRule !^subdomains/ /subdomains/%2%{REQUEST_URI} [L]

If requests to the 'other server' actually resolve to this same server and execute this same .htaccess code, then you will need to exclude those two specific subdomains from this rule using a negative-match RewriteCond, such as:

RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+(\.[^.]+)*)\.example\.com\.?(:[0-9]+)?$
RewriteCond %2 !^(excluded-subdomain1|excluded-subdomain2)$
RewriteRule !^subdomains/ /subdomains/%2%{REQUEST_URI} [L]

Jim

tuarek

6:55 pm on Jun 17, 2010 (gmt 0)

10+ Year Member



thx for answer :)

k, one question

here: excluded-subdomain1 = excluded-sub or excluded-sub.example.com ?

Mario

jdMorgan

12:59 am on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is exactly the same subdomain string as the one to be inserted into the filepath by the RewriteRule, since it is taken from the same "%2" variable.

Jim