I want to rewrite an url with mod_rewrite from http://www.server.com/directory/public to http://www.server.com/directory (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:
<VirtualHost xxx.xxx.xxx.xxx:443>
ServerAdmin [email protected]
ServerName www.server.com
DocumentRoot /var/www/server.com
<Directory /var/www/server.com>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/directory
RewriteRule ^(.*)$ /directory/public/ [L]
</Directory>
</VirtualHost>
Try changing your rewrite rule to this:
You do not need the RewriteCond
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:
<Directory >
block.<Directory >
block.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 addingOptions +FollowSymLinks
.