Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a standard CMS-like RewriteRule set up in my .htaccess:

RewriteRule ^(.+)$ index.php?slug=$1

Let's say I have a directory called foo in the root directory. For some reason, if you hit the page it causes a redirect: redirects to

Removing the directory fixes the problem, but unfortunately, it's not an option. Does anyone know of a workaround?

share|improve this question

migrated from Feb 21 '11 at 21:41

This question came from our site for system and network administrators.

Since foo is a real directory on the filesystem, by default mod_dir will append a slash, triggering an external redirect (as covener mentions in his answer). I explained more about this in an answer on StackOverflow: – w3d Oct 31 at 11:58

2 Answers 2


DirectorySlash off

It's not the rewrite generating the redirect but mod_dir.

share|improve this answer

Before the RewriteRule put:

RewriteCond %{REQUEST_FILENAME} !-d

This will check if directory foo exists, if it does it won't make rewrite rule.

Also, I'm not sure how you got to foo?slug=foo from redirect destination index.php?slug=$1?

Ok, I've checked, you will need one more ruleset before this one to fix missing /

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ index.php?slug=%{REQUEST_URI} [QSA,L]

This should work like a charm.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.