Catalin
Catalin

Reputation: 3

Mod_rewrite wildcard subdomains. Simple question regarding not so simple rewrite rules

basically I'm trying to do this:

subdomain.domain.com -> domain.com/account?user=subdomain

So far so good. I have found this code to do it and works perfect:

RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com$
RewriteRule ^(.*)$ account.php?user=%1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

Now I'm trying to add one more simple rule to it (marked with *). Adding this new rule makes everything fall apart. Nothing works anymore

RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com$
* RewriteRule ^/somepage http://domain.com/anotherpage [E=SUBDOMAIN:%1,L]
RewriteRule ^(.*)$ account.php?user=%1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

Any idea what is going on and how to correct it ?

Thank you Catalin

Upvotes: 0

Views: 311

Answers (1)

Seven
Seven

Reputation: 26

A RewriteRule is subject to the current set of RewriteCond conditions.

So you will have to do something like that:

RewriteCond
RewriteCond
RewriteRule


RewriteCond
RewriteCond
RewriteRule

Upvotes: 1

Related Questions