简体   繁体   中英

Redirect site with .htaccess but exclude two+ folders

According to this answer , you can exclude a single subfolder from a redirect like so:

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

How would I expand that to include two or more separate subfolders?

You can exclude multiple folders with the following code:

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

This will redirect all requests that don't start with the folder /test/ or /my-folder/ to newdomain.com.

Source: based on broken code from here .

It might be easier to read and maintain if you follow a different answer to the question you referenced.

RewriteEngine on

# Do not rewrite these directories
RewriteRule ^(uploads) - [L]
RewriteRule ^(second) - [L]

# Rewrite all other URL
RewriteRule (.*) http://example.com/$1 [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM