I'm trying to redirect all requests to my domain to another domain using mod_rewrite in an Apache 2.2 VirtualHost declaration. There is one exception to this -- I'd like all requests to the /audio
path not to be redirected.
I've written a RewriteCond and RewriteRule to do this but it's not quite right and I can't figure out why. The regular expression contains a negative lookahead for the string "/audio", but for some reason this isn't matching. Here's the definition:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*\.)?mydomain\.net(?!/audio) [NC]
RewriteRule ^(.*)$ <http://www.newdomain.net> [L,R=301]
If I change the RewriteCond to:
RewriteCond %{HTTP_HOST} ^(.*\.)?mydomain\.net/(?!audio) [NC]
(i.e. put the forward slash outside of the negative lookahead part) then it works, but the downside of this is that requests to mydomain.net without a trailing slash will not be redirected.
Can anyone point out what I'm doing wrong?
(Note: the angle brackets around the domain in the RewriteRule bit above are being added by StackOverflow.com -- they are not there in the actual code!)