HTTPS非万维网重定向 [英] https non www redirect

查看:326
本文介绍了HTTPS非万维网重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我所有的网址重定向到的https:// 没有 WWW

WWW

如果有人把的http:// HTTP:/ / ,他们将被重定向到的https:// 的问题就来了,如果他们把的https:// WWW 那么它不重定向到 https://开头的网站

我用我的的htaccess以下,有什么建​​议?

  RewriteEngine叙述上
的RewriteCond%{} HTTPS关闭
的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]

的RewriteCond%{} HTTPS!上
(。*)重写规则的https://%{HTTP_HOST}%{REQUEST_URI} [R = 301,L]
 

解决方案

这一个规则可以利用这两个要求的护理:

 的RewriteCond%{HTTP_HOST} ^ WWW \。 [NC,OR]
的RewriteCond%{} HTTPS关闭
的RewriteCond%{HTTP_HOST} ^(?:WWW \)?(。+)$ [NC]
重写规则^ https://开头%1%{REQUEST_URI} [R = 301,L,NE]
 

请一定要清除在新的浏览器你们俩所示的规则和测试,以避免旧的缓存。

I'm trying to get all my URLs to redirect to https:// without www.

If someone puts in www. or http:// or http:// they are redirected to https:// the problem comes if they put https://www. then it doesn't redirect to https://website

I'm using the following in my htaccess, any suggestions?

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

解决方案

This single rule can take care of both requirements:

RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]

Make sure to remove both of you shown rules and test in a new browser to avoid old cache.

这篇关于HTTPS非万维网重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆