El Dorado
El Dorado

Reputation: 313

Rewrite condition ! being ignored

I'm working on rewrite rules. Every call made to the mobile website should be redirected to the non-mobile version (or in my example, to google) EXCEPT for a few pages. This has to work on several environments but they aren't the issue (asfar as I can see).

What I have:

RewriteCond %{HTTP_HOST} m\.(local\.|lcl\.|dvl\.|uat\.|)testsite\.be$
RewriteCond %{REQUEST_URI} !^/categoryOne
RewriteCond %{REQUEST_URI} !^/categoryTwo
RewriteRule (.*) http://www.google.be/ [L,R=301]

If I surf to: http://m.lcl.testsite.be/categoryOne I get redirected ... Even though http://htaccess.madewithlove.be/ says I shouldn't be.

So I simplified:

RewriteCond %{REQUEST_URI} !^/categoryOne
RewriteRule (.*) http://www.google.be/ [L,R=301]

http://m.lcl.testsite.be/categoryOne

-> I get redirected

RewriteCond %{REQUEST_URI} ^/categoryOne
RewriteRule (.*) http://www.google.be/ [L,R=301]

http://m.lcl.testsite.be/categoryOne

I get redirected (which is good).

http://m.lcl.testsite.be/randomOtherCategory

-> I don't get redirected.

For me it looks like the negated statement is being ignored, which is strange considering I've used it elsewhere in the project aswel.

Any insight ?

Upvotes: 1

Views: 40

Answers (1)

anubhava
anubhava

Reputation: 785128

There might be other rules in your .htaccess changing REQUEST_URI to something else and causing negation based condition to pass.

Try this instead:

RewriteCond %{THE_REQUEST} !/categoryOne
RewriteRule ^ http://www.google.be/ [L,R=301]

THE_REQUEST variable doesn't change its value after other rules.

Upvotes: 1

Related Questions