Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond - AND statement

How to combine RewriteCond statements?

         

Regnum

11:41 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



Hi,

Long time reader, first time poster.

I've been using these forums alot these days to sort out some .htaccess problems I've been having the last days. But now I'm stuck on what should be a simple issue.

When a users enters my site through "subdomain.domain.com" I'd like to redirect him to "http://www.domain.com/index.php?page=subdomain". But only if the query string parameter "page" has a different value then e.g. 'test'.

Here's the code that I use:

#If the requested subdomain is "subdomain"
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]

#AND if the requested page is different from "test"
Rewritecond %(QUERY_STRING)!^page=test [NC]

RewriteRule ^(.*)$ http://www.domain.com/index.php?page=subdomain [R]

Any help is appreciated.

- Regards

Chris

[edited by: jdMorgan at 4:31 pm (utc) on Mar. 6, 2006]
[edit reason] De-linked [/edit]

Regnum

8:56 am on Mar 5, 2006 (gmt 0)

10+ Year Member



Normally, if I understand it correctly, when I have multiple RewriteCond statements before a RewriteRule, they must all match (AND). Unless I specify the [OR] flag.

Strangely enough my code reacts as if the two RewriteCond statements had an [OR].

Update

Ok, the following seems to work:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteCond %{QUERY_STRING}!^page=test&heading_id=([0-9]+)$
RewriteRule ^(.*)$ http://www.domain.com/index.php?page=test [R,L]

- Chris

[edited by: jdMorgan at 4:32 pm (utc) on Mar. 6, 2006]
[edit reason] De-linked. [/edit]