Logo
My Journal
Blog

Timeline

Blog

Exclude folder from htaccess rewrites

When you are running a CMS, or for example a Blog you might also have SEO url’s enabled through .htaccess rewrites. A common problem with these rewrites can be that you are no longer able to install a second application in a subfolder since those foldernames are included in the rewrites and can cause 404 errors.

To prevent the 404 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:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

The line to add to this, to exclude a folder from being rewritten is:

RewriteCond %{REQUEST_URI} !^/(foldername|foldername/.*)$

Simply replace “foldername” with your own subfolder that needs to be excluded from the rewrite. So the complete .htaccess content would become

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(foldername|foldername/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Leave A Comment