如何编辑htaccess的重定向所有TRAFIC,以确保WWW域名 [英] How to edit htaccess to redirect all trafic to secure www domain

查看:156
本文介绍了如何编辑htaccess的重定向所有TRAFIC,以确保WWW域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现以下目标:


  • 重定向所有HTTP://域名.com到https:// www.domain .COM

  • 所有HTTP重定向:// www.domain .COM到https:// www.domain .COM

  • 重定向所有的https://域名.com到https:// www.domain .COM

所以基本上,我所有的交通是其非www或www将被重定向到SSL WWW域名。

So basically, all my traffic be it non-www or www will be redirected to SSL www domain.

编辑:

此外,我有2子,关于HTTP的作品,所以我想实现以上,并保持了2子从上面的重定向规则免费的。

Additionally, I have 2 subdomain that works on http, so I want to achieve the above and also keep the 2 subdomain free from the above redirect rule.

推荐答案

您可以使用以下code根/的.htaccess:

You can use the following code in Root/.htaccess :

RewriteEngine on
#Http to https
#Exclude subdomains
RewriteCond %{HTTP_HOST} !^(sub1|sub2)
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NC,L,R]
#add www on ssl
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]

这将重定向:

http://www.example.com

到SSL

  • https://www.example.com

和第二条规则将增加WWW非WWW请求对SSL,重定向:

And the second rule will add www to non www requests on ssl, redirect :

  • https://example.com

  • https://www.example.com

这篇关于如何编辑htaccess的重定向所有TRAFIC,以确保WWW域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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