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 fr
If you’re using mod_rewrite in a .htaccess file, you just need to specify the URL path without the local path prefix in your patterns. In your case without the leading /
(as you’re in the document root /
):
RewriteRule ^csNewsAd($|/) - [L]
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.
I have GoDaddy hosting, and this issue killed me. I had the same issues over and over again with conflicting .htaccess options in public_html, with my password-protected sub-directory.
I ended up buying another account because I tried about a million different modifications to my .htaccess file, and nothind worked around this problem. I'm sharing my setup and solution, now, just for completeness and clarity. (Just so you know, the account was worth it anyway, so no biggie.)
If it looks like a combination of other's answers, that's because it is. It took ALL of that to work.
Directory structure:
-otherfiles
---public_html
---.htaccess
-----subfolder
---.htaccess
The subfolder .htaccess has password the protect feature, so similar to this:
AuthType Basic
AuthName "Attendance"
AuthUserFile "/home/user/.htpasswds/public_html/attendance/passwd"
require valid-user
The public_html .htaccess originally had this, and it wasn't working (in that it swallowed EVERYTHING and redirected it, so that FatFreeFramework or CodeIgniter was handling it):
RewriteEngine On
RewriteCond $1 !^(index.php|resources|subfolder|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
In order to fix this problem, I added two lines to my public_html .htaccess file. And so you're not guessing as to where, I'll show the whole file again:
RewriteEngine On
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(subfolder|subfolder/.*)$
ErrorDocument 401 default
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
I'm pretty sure that you have already ruled this out, but since I came here for the same exact issue I wanted to share it with you: in my case the problem was actually on the permissions of - apparently, not being able to access the folder, the exclusion was being ignored.
RewriteCond %{REQUEST_URI} !^/(csNewsAd|csNewsAd/.*)$
instead of
RewriteRule ^/csNewsAd($|/) - [L]
This is the #1 google result and the wrong answer.
The correct answer is adding this before the Wordpress directives.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>