Apache重写删除“www”不工作(全局)

我把Apache Server Configs全局.htaccess文件放在我的Web服务器上,如/etc/apache2/apache-server-configs.conf 。 然后在我的/etc/apache2/apache2.conf文件中,我已经得到了这个文件的结尾:

 # Include of directories ignores editors' and dpkg's backup files, # see the comments above for details. # Apache Server Configs Include apache-server-configs.conf # Include generic snippets of statements Include conf.d/ # Include the virtual host configurations: Include sites-enabled/ 

正在包含apache-server-configs.conf文件,但是这段代码无法工作:

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

RewriteEngine on这个块上面有一个RewriteEngine on语句,几行)如果我把它放在单个域的.htaccess文件中,它就像预期的那样工作。 但在全球范围内,它什么都不做。 我试图使用RewriteLog进行debugging,当我访问我的网站时,日志文件是空的。

我错过了什么?

Debian 7.5,apache 2.2.22

编辑8/2/2014:添加更多的信息


还值得注意的是,如果我在/etc/apache2/apache2.conf包含一个conf文件,并且将所有的RewriteRule调用放在包含的文件中,它们都不会工作。 在conf文件中的其他东西工作得很好,但重写不。

test.com虚拟主机文件:

 <VirtualHost *:80> # Admin email, Server Name (domain name), and any aliases ServerAdmin [email protected] ServerName test.com ServerAlias www.test.com Options -Indexes <IfModule mpm_itk_module> AssignUserID bob bob </IfModule> # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /home/bob/www/test.com # Log file locations LogLevel warn ErrorLog /home/bob/logs/test.com/error.log CustomLog /home/bob/logs/test.com/access.log combined </VirtualHost> <VirtualHost *:443> SSLEngine On SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key #SSLCertificateChainFile /etc/ssl/test.com/ca-bundle ServerAdmin [email protected] ServerName test.com ServerAlias www.test.com Options -Indexes <IfModule mpm_itk_module> AssignUserID bob bob </IfModule> DocumentRoot /home/bob/www/test.com ErrorLog /home/bob/logs/test.com/error.log CustomLog /home/bob/logs/test.com/access.log combined </VirtualHost> 

根据Apache文档 ,重写条件不是默认由子虚拟主机块inheritance。 从文档中获取,build议可以设置为像这样inheritance:

 RewriteEngine On RewriteOptions Inherit 

您必须在每个需要inheritance您在主configuration文件中设置的重写规则的虚拟主机上进行设置。