.htaccess & Wordpress: Exclude folder from Rewrite

2019-01-06 17:42发布

I have this .htaccess file in Wordpress. It's located at /public_html/ (web root). I need to exclude a folder (csNewsAd) from the rewrite engine. I've tried this, based from another question similar here at SO, but didn't work at all.

AddHandler x-httpd-php5 .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/csNewsAd($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Any suggestions?

More data

There's another .htaccess inside /csNewsAd for password protection:


AuthName "Clasificados"
AuthType "basic"
AuthUserFile /home/ig000192/public_html/csNewsAd/.passwd
Require valid-user

14条回答
仙女界的扛把子
2楼-- · 2019-01-06 18:09
RewriteCond %{REQUEST_URI} !^/(csNewsAd|csNewsAd/.*)$ 

instead of

RewriteRule ^/csNewsAd($|/) - [L] 
查看更多
3楼-- · 2019-01-06 18:12

I first started doing this with Rails. At the top of the rails .htaccess are the following two lines.

# RewriteCond %{REQUEST_URI} ^/notrails.*
# RewriteRule .* – [L]

When I finally followed their example it worked.

I wanted to exclude images, javascripts, stylesheets, css, images-global, js-global (etc) so I changed the above to.

RewriteCond %{REQUEST_URI} ^(images|javascripts|stylesheets|css|images-globa|js-global|js).*
RewriteRule .* – [L]

And it worked the way I needed.

We won’t talk about how it is that I have so many different javascript, stylesheet and images folders….

But this does make my “error” file less painful. If someone adds an image file that doesn’t exist, my dispatch doesn’t have to process it.

查看更多
登录 后发表回答