Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm doing the following:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public
RewriteRule /(.+) /public/$1

And it maps like this:

/           => index
/.+         => /public/$1
/public/.*  => Doesn't map, but it should map to /public/public/$1

I don't wan't /public/ to be accessible, how can I do that?

share|improve this question
So you want them to be able to be rewritten to it but not access it directly? What problem could that possibly solve? –  MDMarra Nov 12 '11 at 12:07
Being able to have a file named public in the public directory and be accessed from the root. –  Zequez Nov 12 '11 at 17:13

1 Answer 1

Just write, as the #1 rule :

RewriteRule /public/(.*) - [F,L]

Then if someone wants to access to /public/ there will be a FORBIDDEN. After this rule, you may apply your rules.


So your rules may look like:

RewriteEngine On
RewriteRule /public/(.*) - [F,L]
RewriteCond %{REQUEST_URI} !^/public
RewriteRule /(.+) /public/$1
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.