Php apache将http重定向到不带www的https
正在尝试将所有Php apache将http重定向到不带www的https,php,apache,.htaccess,redirect,mod-rewrite,Php,Apache,.htaccess,Redirect,Mod Rewrite,正在尝试将所有http和none-www流量重定向到https(带或不带www)。 使用.htaccess和apache VirtualHost文件: 虚拟主机文件 <VirtualHost *:80> ServerName adi-md.co.il ServerAlias www.adi-md.co.il 选项2 RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC] Rewr
http
和none-www
流量重定向到https
(带或不带www)。
使用.htaccess
和apache VirtualHost
文件:
虚拟主机文件
<VirtualHost *:80>
ServerName adi-md.co.il
ServerAlias www.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个,但它们没有提供答案(3个交易中有2个是www对无www)
尝试使用以下方法:
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} =on
RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,NE]
这基本上首先检查您是否启用了www
和HTTPs
。如果是,它将切换回HTTP
并删除www
在测试之前,请确保清除缓存。将http重定向到不带www的https的两个简单规则:
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
不知何故,这没有起到作用……我更新了我的问题的
。htaccess
文件签出是否可以使用这些规则。但在使用本地域主机时忽略它们?
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} =on
RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]