我已经获取了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
语句,有几行)如果我将它放在单个域的.htaccess
文件中,它会按预期工作。但在全球范围内,它什么也没做。我尝试使用调试RewriteLog
,但访问我的网站时日志文件为空。
我错过了什么?
Debian 7.5,阿帕奇 2.2.22
编辑 8/2/2014:添加更多信息
还值得注意的是,如果我在其中包含一个 conf 文件/etc/apache2/apache2.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 文档,重写条件默认情况下不被子 Virtualhost 块继承。取自文档,建议可以将它们设置为继承,如下所示:
您必须在需要继承您在主配置文件中设置的重写规则的每个虚拟主机上进行设置。