Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to rewrite an url with mod_rewrite from to (where directory would be then directing to directory/public)

I've tried several things but I can't figure it out. Here is my configuration:

            DocumentRoot /var/www/

        <Directory /var/www/>
            RewriteEngine on
            RewriteCond %{REQUEST_URI} ^/directory
            RewriteRule ^(.*)$ /directory/public/ [L]
share|improve this question
up vote 1 down vote accepted

Try changing your rewrite rule to this:

RewriteRule ^/directory(.*) /directory/public$1 [NC,L]

You do not need the RewriteCond

share|improve this answer
Worked flawlessly! Thanx! – Ezeyme Jan 17 '12 at 10:07

Within a <Directory > context, URIs in rewrite rules do not start with a /.

This is also true for URIs in rewrite rules in .htaccess files because they are implicitly in a directory.

The relevant part of the documentation is titled "Per-directory Rewrites"

To fix this you can do one of:

  1. Move the RewriteRule and RewriteCond out of the <Directory > block.
  2. Remove the leading slash from the RewriteCond and the second part of the RewriteRule.
  3. Follow Ivmisooners' suggestion but also move the RewriteRule out of the <Directory > block.
  4. Follow Ivmisooners' suggestion but remove the leading slashes from the RewriteRule.

If it were my choice, I would use option 3.

From my reading of the documentation page linked above, it seems to suggest that you must have Options FollowSymLinks enabled for RewriteRules to work in a per-directory context. I have never tested this myself. If you have troubles getting RewriteRules to work at all inside that <Directory > block, try adding Options +FollowSymLinks.

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.