It's Friday - what a day to visit jfoobar!

Jfoobar Labs

At jfoobar labs you will find "stuff" that is either cool, useful or for learning purposes. We hope to create a pretty nice selection over time. Remember, we need it to be fun.

Snippet - Exclude folder from htaccess rewrites

  • Type: Code Snippet
  • Compatible: Diverse
  • Last update: 2008-11-22

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]

There are 7 comments posted.

# 1 - Posted by: chali on 2009-03-27 07:50:39

Thanks you :)

You saved my day.

# 2 - Posted by: Eiso on 2009-04-30 20:02:47

Thank you much appreciated!

# 3 - Posted by: Axel Giqueaux on 2009-06-09 13:28:37

Thank you, i can now execute my cgi scripts without trouble.

# 4 - Posted by: Moblie price on 2009-06-15 17:03:23

I can't execute this code in my htaccess. Can i use this code with lighttpd?

Re: Fantastic

# 5 - Posted by: Luke Hartman on 2009-07-28 22:48:11

Thanks for this. It helped immensely. To exclude multiple folders, the condition can be modified a little:

RewriteCond %{REQUEST_URI} !^/(folder1|folder2|folder3).*$

Re: phpfox

# 6 - Posted by: Ray on 2009-09-21 02:51:39

Thank you very much for this helpful snippet! This also worked for phpfox, just remember to add it twice to each set of rewrite commands.

Thank you again!!

# 7 - Posted by: Katherine on 2009-11-29 23:55:56

Hi, I was wondering if you would know how to exclude a folder within a folder?

So not just example.com/folder1, but example.com/folder1/folder2/folder3

Thanks.

Help for creating beautiful comments.

Enter Your Details:
Enter Your Comments:
I'm finished with the form Your form will be checked and you'll get a preview.
moovur promo

JFoobar friends on Twitter

Follow JFoobar on twitter

Sponsored Links

Latest Comments

Aaron wrote:
2009-12-23 13:19:22 - Genius! Thanks, Wilco. I've been dying to take .
Posted in How to downlo .
Amy Stephen wrote:
2009-12-22 18:39:37 - Happy Birthday to one of Joomla!'s most noble - .
Posted in Mister Joomla .
Antonie de Wilde wrote:
2009-12-22 09:30:26 - Congrats Robin. Have a good day and watch out w .
Posted in Mister Joomla .
Robert wrote:
2009-12-22 08:51:02 - Happy Birthday Robin .
Posted in Mister Joomla .
Arno wrote:
2009-12-22 08:43:28 - Happy Birthday Robin, love your suit, you wife .
Posted in Mister Joomla .
Brian Teeman wrote:
2009-12-22 00:17:41 - Happy Birthday Robin, Welcome to the big four oh .
Posted in Mister Joomla .