我正在使用Apache 2.4。我面临一个奇怪的问题。我在虚拟主机中定义了一些重写规则,并且它运行正常。但是如果我把" RewriteEngine放在"在我的.htaccess文件中,virtualhost中定义的重写规则不再有效。
我尝试从虚拟主机中删除规则并将其粘贴到.htaccess中但它不起作用。出于某种原因,它只适用于虚拟主机。
我做错了什么?
以下是我的虚拟主机:
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/test/sites/test.com/public_html
<Directory />
Require all granted
AllowOverride All
# Redirect http to https
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(blog) [NC]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/test/sites/test.com/public_html
SSLEngine ...
<Directory />
AllowOverride All
Require all granted
ErrorDocument 404 /404.html
# Rewrite .html to .php
RewriteEngine on
RewriteCond %{REQUEST_URI} !(blog) [NC]
RewriteCond "$1.php" -f
RewriteCond "$1.html" !-f
RewriteRule "^(.*).html$" "$1.php"
</Directory>
</VirtualHost>