301 redirect all traffic to new site except for certain folders

If you need to redirect a whole site to a new url except for one or more folders, then the script below will work for you.

When would you use this?
Let's say you have domainA.com and want to redirect everything to domainB.com but you are still hosting some images or pages that you still want/need to access on domainA.com

In the example below, we are redirecting ALL pages EXCEPT for anything in the folder: /clients/ and /wordpress/wp-content/uploads/

You see in the example below we are hosting a client billing section in /clients/ and we have images within the client section stored under the wordpress uploads folder.

So this allows the whole of the site to redirect to our new site but we still have access to some of the old assets.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/clients/.*
RewriteCond %{REQUEST_URI} !^/wordpress/wp-content/uploads/.*
RewriteRule .* https://www.domainB.com [R=301,L]
  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

Solving the ERR_BLOCKED_BY_XSS_AUDITOR in Chrome

You are reading this article because you have saved something in wordpress and received an error...

Additional security/performance settings for htaccess

Below is some additional rules for your htaccess file which provides some performance and...

Forcing SSL and WWW in htaccess

Use the following code in the htaccess file for making sure that all pages served up are www and...

301 redirect all traffic from domain A to the root of domain B

If you need to 301 redirect all the traffic from olddomain.com to the index page of newdomain.com...

Fix WordPress 404 Errors on Password Protected Directories

You are reading this article becasue you have applied password protection on the wp-admin...