Take the 2-minute tour ×
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:

http://www.mysite.com/foo --> http://www.mysite.com/foo?slug=foo

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 serverfault.com Feb 21 '11 at 21:41

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

2 Answers 2

before the RewriteRule put

RewriteCond %{REQUEST_FILENAME} !-d

this will check if directory foo exists, if it does it wont 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 charm

share|improve this answer

Try "DirectorySlash off" -- not rewrite generating the redirect but mod_dir.

share|improve this answer

Your Answer

 
discard

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