.htaccess
将所有流量重定向到https
。我正在使用此答案中的示例:需要将所有流量重定向到https。RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
这个对我没有任何重定向的作用。我把它放在了var/www
,但似乎没有任何效果。我哪里做错了?
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
如果这是你的htaccess文件中唯一的规则,并且它在你的文档根目录下,那么你需要检查几件事情,因为这些规则是正确的。
Make sure mod_rewrite is loaded. There should be a line in your httpd.conf
file that looks something like:
LoadModule rewrite_module modules/mod_rewrite.so
Make sure it's uncommented.
Make sure the directory that your htaccess file is in (should be your document root) is allowed to override server settings via htaccess. In your vhost or server config, there should be something along the lines of
<Directory "/var/www/">
AllowOverride All
... (some other stuff)
</Directory>
Make sure the AllowOverride
is at least FileInfo
Make sure your document root is actually where your htaccess file is in. Your vhost config should have a line like:
DocumentRoot /var/www/
Make sure the document root is for the right vhost. If you have separate vhosts for SSL and non-SSL, make sure the htaccess file is in the document root for the non-SSL vhost.
httpd.conf
文件是空的,Ubuntu 配置不同吗? - Paul DessertAllowOverride
被设置为none,而我将其更改为All,重新启动Apache,但我仍然遇到问题。 - Paul Dessert
mod_rewrite
。 - vee