mod_rewrite将文件添加到url

以下重写将http://example.com/redirect到http://example.com/www/www.example.com/public_html,而不是http://www.example.com/ 。 /www/www.example.com/public_html是DocumentRoot 。

# Rewrite Rules for Example RewriteEngine On RewriteBase / # Redirect from example.com to www.example.com RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

这个redirect是在一个VirtualHost *:80的设置:

 ServerName example.com ServerAlias www.example.com ServerAdmin [email protected] Options +FollowSymLinks DocumentRoot /www/www.example.com/public_html and the rewrite is inside <Directory /> 

任何想法,为什么会这样做? 我查看了Apache手册 ,它说在你的RewriteCond中使用$ {HTTP_HOST}会把主机添加到RewriteRule而不是URL-Path 。 那么这是一个非常常见的重写,我从来没有见过这种情况发生。

问题是<Directory /> 。 一旦我更新到<Directory /www/www.example.com/public_html>它工作得很好。