I am trying to redirect my entire domain except 1 directory - my forum.
After tons of searching online, I have come up with this:
RewriteEngine on
RewriteCond $1 !^/forums
RewriteRule (.*) http://www.mynewdomain.com/$1 [R=301,L]
The redirect portion of the code works perfectly. The problem is that mydomain.com/forums still redirects to the new domain.
One thing that is important about the redirect is that it needs to preserve the path. That is to say, if someone tries to visit mydomain.com/test it should redirect them to mynewdomain.com/test.
Does anyone know what is wrong with the code above?
What’s wrong with the code is the RewriteCond. It should be RewriteCond %{REQUEST_URI} !^forums/ as there is NO $1 available to the RewriteCond (it’s created by the following RewriteRule).