Redirect site to another URL except for a specific directory

You are moving your site to another domain. You want to redirect users to the new domain. But you have a script on a directory that you still want to access on the old domain.

The necessary lines that must be added to your .hatccess file are:

RewriteEngine on
RewriteRule !^(script_directory){REQUEST_URI} [R=301,L]

If you want to redirect two directories, separate them with | :

RewriteEngine on
RewriteRule !^(directory1|directory2){REQUEST_URI} [R=301,L]

The code will keep the path – for example will be redirected to

RewriteRule Directive

Leave a Reply