简体   繁体   中英

Redirect directory but exclude a subdirectory

So we have a wordpress site where we are using a plugin to push all files in the wp-content/uploads directory to Amazon S3. However, we use a video plugin which requires the use of the uploads directory in a temp folder to generate video thumbnails.

Due to the fact that we have a rewrite rule (as seen below) to redirect /wp-content/uploads to the relevant S3 address which is vital to get the backend functioning correctly, it is causing problems with the temp folders.

RedirectPermanent /wp-content/uploads/ [amazonbucketurl]/wp-content/uploads/

What we need is a redirect rule which can go in the .htaccess file and exclude /wp-content/uploads/thumb_tmp from the blanket redirect rule for /wp-content/uploads.

Any help will be great!

Try this rule:

RedirectPermanent /wp-content/uploads/(?!thumb_tmp).* [amazonbucketurl]/wp-content/uploads/

Here (?!thumb_tmp) is used to exclude thumb_tmp sub folder from rewriting.

This worked in the end!

RewriteCond %{REQUEST_URI} !^/wp-content/uploads/thumb_tmp/.*
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/thumb_tmp$
RewriteRule ^wp-content/uploads/(.*)$ http://dingvideo-europe-array.s3.amazonaws.com/wp-content/uploads/$1 [R=301,L]

It works by running the rewrite rule on the uploads folder but excluding the thumb_tmp directory.

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