我正在尝试更改我的apache2服务器配置,我确信它不是最佳的。现在我将所有AllowOverride设置为None。我想保持该配置以设置全局规则并增加页面加载时间。
但是,现在的问题是我使用单独的虚拟主机和带.php文件的目录将www.example.com重定向到https://www.example.com。我确定这不是最佳选择。我更喜欢使用mod_overwrite。
根据我的阅读,如下所示的规则集将启用此功能。但是,如果我想保留AllowOverride None,我想知道在哪里放置此代码。
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我相信如果我在正确的位置添加这样的规则集,我也可以禁用我用来重定向的其他虚拟主机。
答案 0 :(得分:1)
您应该将重写规则放在
中<Directory /some/where>
[...]
</Directory>
在apache配置中阻止。因此,您不需要任何.htaccess文件,因此不会更改为AllowOverride。