Redirect the entire site except one directory to the new site - apache.htaccess

I am trying to move my current site to a new domain except for the ONE directory.

Example:

  • current site: oldsite.olddomain.example
  • new site: newdomain.example

So, I know that I can create a .htaccess redirect entry for this, and it works, but I want an ONE exception - I DO NOT want to redirect a specific directory. I still want this to work:

http://oldsite.olddmain.example/myspecialdirectory/… and each file and directory below it.

Can anyone help? Thanks!

+4
source share
1 answer

Try this mod_rewrite rule in the .htaccess file at the root of the oldsite.olddomain.example document:

 RewriteEngine on RewriteRule !^myspecialdirectory($|/) http://newdomain.example%{REQUEST_URI} [L,R=301] 
+3
source

All Articles