Redirect site with .htaccess, but exclude one folder

I want 301 to redirect the entire site, but exclude everything in the folder named /uploads that exists in the /root directory.

I googled about this, but didn’t think of anything, or I didn’t think that what I saw was correct.

Can we crack this?

+54
redirect apache .htaccess
Aug 05 '10 at 10:59
source share
4 answers

Try the mod_rewrite rule:

 RewriteEngine on RewriteRule !^uploads($|/) http://example.com%{REQUEST_URI} [L,R=301] 

This rule matches any URL path that does not start with /uploads or /uploads/ (the master is missing in the template / due to the removal of the path prefix when used in .htaccess files) and redirects the request to the corresponding path in example.com.

+63
Aug 05 '10 at 11:01
source share

The simple answer is I just stumbled upon myself.

At the top, before any other calls, add the following

 RewriteRule ^(uploads) - [L] 
+54
Aug 27 '12 at 15:30
source share

I think you want this:

 RewriteEngine on RewriteCond %{REQUEST_URI} !^/uploads/ RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

If you get 500 Internal Error , double check that you have a space between } and ! in the second line.

+24
Aug 05 2018-10-11T00:
source share

Mod-alias solution

Redirect everything except a specific folder

Add the following line to your root / .htaccess:

 RedirectMatch 301 ^/((?!uploads).*)$ http://newdomain.com/$1 

This will redirect all pages (excluding / uploads / *) from the old domain to the new domain.

+10
Apr 29 '16 at 18:13
source share



All Articles