mod_rewrite:一个服务器上的多个域,mod_rewrite拒绝在一个服务器上工作

时间:2013-04-22 06:48:33

标签: apache mod-rewrite virtualhost

我有一台服务器使用Apache的虚拟主机恶作剧从单个IP地址为多个域提供服务。如果从URL中省略了三个站点,则需要将其中的三个站点重定向到www

我在每个域的.htaccess文件中都有以下规则:

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

这适用于三个中的两个,但第三个完全不符合。我知道.htaccess正在受到攻击,因为框架要求所有匹配都通过index.php进行路由......这种情况正确发生。因此,它不是权限,.htaccess在每个域上都相同(或多或少)。我甚至考虑过缓存(即使这没有任何意义......绝望让位于精神错乱!)

如果您有任何线索,请帮助我。

根据要求,这是完整的vhost配置和.htaccess文件......

vhost配置:

<VirtualHost *:80>
        ServerAdmin me@gmail.com
        DocumentRoot /var/www/example.com
        ServerName www.example.com
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/example.com>
                Options FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

.htaccess档案:

# BEGIN example.com

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]

####################################################
# If requested URL-path plus ".php" exists as a file
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# Rewrite to append ".php" to extensionless URL-path
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
####################################################

# redirect to RoutingHandler
RewriteRule ^.*$ /index.php [NC,L]

</IfModule>

# END example.com

请记住,还有另外两个域以相同的方式设置......它们都可以解决零问题。

1 个答案:

答案 0 :(得分:0)

我知道这是一个老问题,但谷歌在找同样问题的答案时把我带到了这里。 在搜索了apache的文档后,我发现: AllowOverride Directive

  

当此指令设置为None时,则完全忽略.htaccess文件。在这种情况下,服务器甚至不会尝试读取文件系统中的.htaccess文件。

所以我在<Directory /var/www/example.com>部分中将“AllowOverride None”更改为“AllowOverride All”并且有效。