3

I'm trying to redirect all requests except those beginning with certain paths.

for example,

http://www.example.com/mypath1 shouldn't redirect

http://www.example.com/mypath2 shouldn't redirect

Everything else should redirect

So far ive tried getting it working using just one of the exception paths like this:

RewriteRule ^(?!/mypath1/).*$ http://www.google.com/? [R=301,L]

and like this:

RewriteCond %{REQUEST_URI} !^/mypath1/.* [NC]
RewriteRule ^.*$ http://www.google.com/? [R=301,L]`

and like this:

RewriteCond %{REQUEST_FILE} !^/mypath1/.* [NC]
RewriteRule ^.*$ http://www.google.com/? [R=301,L]

However everything I try is just redirecting all requests. Does anyone know how to do this?

cowls
  • 24,013
  • 8
  • 48
  • 78
  • 1
    When I put the 2nd rule (with the REQUEST_URI) in my vhost conf and it works as expected. You sure there's not some other rule somewhere that's interfering? – Jon Lin Jan 03 '12 at 19:06

1 Answers1

1

I've managed to resolve the issue, the request I was making was getting redirected later in the apache config to an error page which was then being caught by the catch all redirect.

If anyone else is having similar issues I recommend using the apache RewriteLog as this helped pinpoint the issue. To do this just add this in your VHOST:

RewriteEngine on
RewriteLog "C:/devenv/Apache2/logs/rewrite.log"  
RewriteLogLevel 2
cowls
  • 24,013
  • 8
  • 48
  • 78