Exclude folder from htaccess rewrites on WordPress blog
A couple of months ago I tried without success to share some video files on my web domain. I created a new folder, I copied those avi files there but when pointing the browser to that files it gave me that 404 error, page not found.
I took me a while to understand that WordPress especially is rewriting the .htaccess so you no longer can use any other file, except the files accepted by WordPress on your web domain. This is why so many people are installing WordPress blog on a sub-domain or just in another folder and not directly into the root.
When using a CMS (Content Management System) like ModX or WordPress the problem you’re facing is that you’re no longer able to install a second application or to use some sort of files because the rewrites can cause 404 error.
I presented at that time an easy to implement solution for excluding of those desired files from .htaccess rewrite on a WordPress blog:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Today I come with a solution for excluding an entire folder from being rewritten in WordPress. The only thing you have to do is adding the following line to the previous block of code:
RewriteCond %{REQUEST_URI} !^/(foldername|foldername/.*)$
To make it work just replace “foldername” with your own that needs to be excluded from the rewrite. Here the entire block oh code you have to implement into your .htaccess files:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(foldername|foldername/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Hint: I am using WinSCP for accessing my ftp accounts and modify .htaccess files. It’s free and is a very good tool. And, by the way in comparison with others I tried is the only one showing me .htaccess files on the server. Tried before with Total Commander (very handy tool, too) but with no success.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.


Thanks, but it doens’t seem to work in WP3.0?
(that version has a bit different htaccess structure?)
for me is working just fine and I am using wp 3.0.
I’ve seen this solution a number of places, but it hasn’t worked for me. Do I need to clear the cache? does something need to activate the .htaccess file?
It just doesnt work
Since this is the top Google result for this problem. I thought that I’d share that this didn’t work for me either…
But I did find this solution that did work for me here:
http://stackoverflow.com/questions/163302/how-do-i-ignore-a-directory-in-mod-rewrite
- RewriteRule ^foldename – [L,NC]
(The – means do nothing.)
(The L means this should be last rule; ignore everything following.)
(The NC means no-case (so “FOLDERNAME” is also matched).)
I put that one line in before the “RewriteEngine On” line in my .htaccess file and it worked a treat. Hope that helps.
Oh I should add that that solution above matches all folders AND filenames that begin with “foldername”.
As mentioned in the original URL, if you just wanna exclude that specific folder you should adjust it to:
- RewriteRule ^foldename(/|$) – [L,NC]
did not work for me either. wordpress 3.0.5
Did not work for me either. Are you sure this is still valid?
What worked for me:
Empty the contents of the .htaccess
Then rewrite permalinks in WP. If the folder is already there, WP does it correctly. If you add it after WP writes the .htaccess, then it seems to cause problems.
Erum, what you say is not clear though.
If you come with more info will be great and hopefully helpful :)
Thanks.
Sorry, never saw the above comment. Delete htaccess. Make sure the folder you want excluded already exists. Set permalinks via WP admin. Since the folder you want excluded already exists, WP will take that into account automatically.