Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite help needed

I'm doing something wrong and not sure what, trying to redirect subdomains

         

catalin

7:02 pm on Jul 18, 2011 (gmt 0)

10+ Year Member



Hello,

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 [domain.com...] [E=SUBDOMAIN:%1,L]
RewriteRule ^(.*)$ account.php?user=%1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]


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

Thank you
Catalin

lucy24

10:39 pm on Jul 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Preliminary queries:

In your actual htaccess, do you repeat the set of conditions before each rule? Otherwise, they will apply only to the first rule in a list. The following rules will execute regardless, since they don't have conditions of their own.

Is the new rule meant to be instead of or in addition to the immediately following rule?

:: trying to buy time while waiting for fluent Apache speakers to come back from business lunch ::

g1smd

10:59 pm on Jul 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What's missing from the code is the comments explaining what the code is supposed to do.

Use example.com to stop the forum auto-linking.

RewriteRule cannot see the leading slash of the request hence the pattern never matches.

RewriteRule with a domain name in the target produces a 302 redirect.

catalin

9:19 am on Jul 19, 2011 (gmt 0)

10+ Year Member



lucy your preliminary questions solved my problem. I was expecting for RewriteCond to apply to all the RewriteRules following it. Seems not so I will have to apply all RewriteConds to each of the RewriteRules

Thank you