【发布时间】:2017-06-07 05:38:50
【问题描述】:
尝试将所有 http 和 none-www 流量重定向到 https(带或不带 www)。
使用.htaccess 和apache VirtualHost 文件:
虚拟主机文件
<VirtualHost *:80>
ServerName adi-md.co.il
ServerAlias www.adi-md.co.il
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTP_HOST} ^adi-md.co.il
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,NE]
#RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
#RewriteRule (.*) https://www.%1%{REQUEST_URI} [L,R=301]
#RewriteCond %{HTTP_HOST} ^www.adi-md.co.il
选项 1
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^adi-md.co.il
选项 2
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://www.%1%{REQUEST_URI} [L,R=301]
仅输入adi-md.co.il 时,您将获得服务器的默认页面。
如何解决它,以便所有流量都重定向到 https 以及 none-www 请求??
注意: 我看过这 3 个,但它们没有提供答案(2 out 3 处理 www 到 none-www)
apache redirect http to https and www to non www
http to https apache redirection
Redirect from http to https without www using .htaccess
【问题讨论】:
标签: php apache .htaccess redirect mod-rewrite