If you have an application or CMS running, you might have SEO url’s enabled through .htaccess rewrites. Now installing a second application in a subfolder on the same domain can cause 404 errors. This is because all subfolders follow the rules specified in the root htaccess file.
To prevent the errors, there is a single line which you can add to exclude such a foldername from being rewritten. Below a default .htaccess file for WordPress:
To prevent the errors, you can add the below single line to your rewrites to exclude that particular application folder.
RewriteCond %{REQUEST_URI} !^/(folder1|folder2/.*)$
Simply replace “folder1” with your own subfolder name that needs to be excluded from the rewrite.
In a default WordPress installation, it would look like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(folder1|folder2/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
One thought on “Exclude Certain Folders from htaccess Rewrite Rules”
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.