这个问题已经被问到,但我没有find解决scheme。 我有非常小的Apache经验。 我需要build立我的服务器采取以下要求
http://, http://www. and https:// and convert them to https://www.
到目前为止,这是我的工作。
RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
但是,它提供了一个额外的万维网。 当我键入http://www.domain.com (所以它最终在url https://www.domain.com中看起来像这样)。 我需要做些什么来使这个工作正常? 而且,我将它放在全局configuration编辑configuration文件httpd.conf中。 这是正确的地方吗? 它看起来像我可能把它放在虚拟主机编辑指令文件,但我不知道? 再一次,我很新的在Apache。 谢谢你的帮助。
这将工作
RewriteEngine on # redirect all http -> https RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^([az.]+)$ [NC] RewriteRule ^/(.*)$ https://www.%1/$1 [R=301,L]
第一部分是你有什么可以http-> https罚款
下一节
第一行将忽略www第二行将忽略,如果他们input一个IP地址(可以删除,如果你想)第三做redirect。
这应该照顾两者:你可以把它放在你的.htaccess或httpd.conf中
<IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>