简体   繁体   中英

Apply rewrite rule for all but all the files (recursive) in a subdirectory?

I have an .htaccess file in the root of the website that looks like this

RewriteRule ^some-blog-post-title/ http://website/read/flowers/a-new-title-for-this-post/ [R=301,L]
RewriteRule ^some-blog-post-title2/ http://website/read/flowers/a-new-title-for-this-post2/ [R=301,L]

<IfModule mod_rewrite.c>
RewriteEngine On

## Redirects for all pages except for files in wp-content to website/read
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/wp-content
RewriteRule ^(.*)$ http://website/read/$1 [L,QSA]

#RewriteRule ^http://website/read [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
  1. My intent is to redirect people to the new blog post location if they propose one of those special blog posts.
  2. If that's not the case then they should be redirected to http://website.com/read .
  3. Nothing from http://website.com/wp-content/ * should be redirected.

So far conditions 1 and 3 are being met. How can I meet condition 2?

Note: I want to redirect to /read even for content that exists to prevent any images, CSS, or javascript from working, except those in /wp-content

Make your first rule as:

## Redirects for all pages except for files in wp-content to website/read
RewriteRule !^wp-content/ http://website.com/read%{REQUEST_URI} [NC,L,R=302]

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