Forum Moderators: phranque

Message Too Old, No Replies

Exception for subdirectories

Exception for more than one subdirectory won't work

         

sebelk

1:43 am on Jan 26, 2008 (gmt 0)

10+ Year Member



Hi,
I have a site, eg: www.mysite.com and other www.anothersite.com.
I want that al request for www.mysite be redirected to www.anothersite.com. But I want to have an exception for subidirectory /alpha. So I wrote this .htacess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}!^/alpha(.*)$
RewriteRule (.*) [anothersite.com...] [R=301,L]

It works..... but if I want a /beta directory be skipped, it doesn't work... well at least, how I did:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}!^/alpha(.*)$ [OR]
RewriteCond %{REQUEST_URI}!^/beta(.*)$
RewriteRule (.*) [anothersite.com...] [R=301,L]

Apache ignores rewriting in this case... why?

Also I tried this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}!^/alpha(.*)$
RewriteRule (.*) [anothersite.com...] [R=301,L]
RewriteCond %{REQUEST_URI}!^/beta(.*)$
RewriteRule (.*) [anothersite.com...] [R=301,L]

And didn't work either...

How can I solve it?

Thanks in advance!

sebelk

1:53 am on Jan 26, 2008 (gmt 0)

10+ Year Member



Well I find by myself the answer :)

I did:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}!^/alpha¦beta(.*)$
RewriteRule (.*) [anothersite.com...] [R=301,L]

And it worked!

But anyway I don't understand why other methods didn't work

:S

jdMorgan

3:16 am on Jan 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your rule failed Because you used the [OR] flag to combine negative-match patterns.

For example, what is the result of the following logical statement?
If color NOT(Blue) OR NOT(Red) then True.

Tell me what one color you'd name to make that statement False.
Hint: There is no color you can name that is both red and blue...

In general, negative-true patterns should be ANDed, while positive-true patterns are usually ORed.

If you are interested in further studies of combinatorial logic, try searching for "DeMorgan's Theorem" which establishes the following:
a OR b == NOT ( NOT(a) AND NOT(b) )
a AND b == NOT ( NOT(a) OR NOT(b) )

This comes in handy when trying to simplify RewriteConds, and occasionally can make a seemingly-impossible function much easier to implement.

Jim