holysir的gravatar头像
holysir 2015-11-11 14:07:52

如何实现http请求跳转到https协议访问网站?

我的网站申请了https协议,但是输入http://站点  还是可以访问,如果做到若输入的是http,自动切换到https.

像百度:https://www.baidu.com,如果你输入http://www.baidu.com  它会自动切换到https://www.baidu.com

所有回答列表(3)
最代码官方的gravatar头像
最代码官方  LV167 2015年11月11日

如果是nginx的话,可以通过rewrite语法实现

server {
 listen       80;
 server_name  http://zuidaima.com;
 rewrite ^(.*) https://www.zuidaima.com$1 permanent;
}

线上亲测可用。

其他web server原理类似。

雨、小雨的gravatar头像
雨、小雨  LV8 2015年11月12日

加一个公用的过滤器做301可以吧

whoony的gravatar头像
whoony  LV2 2015年11月12日

tomcat web.xml里加下面代码试试

<security-constraint> 
       <web-resource-collection > 
              <web-resource-name >SSL</web-resource-name> 
              <url-pattern>/*</url-pattern> 
       </web-resource-collection>
       <user-data-constraint> 
              <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
       </user-data-constraint> 
</security-constraint>

最近浏览
spy0505 2020年7月16日
暂无贡献等级
wei112233  LV15 2020年6月4日
interface  LV22 2018年7月12日
shuiyu  LV3 2018年7月4日
黯然飘尘  LV2 2017年3月23日
jieke  LV10 2016年2月17日
lvzw  LV1 2015年12月20日
arvinsang  LV2 2015年12月9日
tonnycose  LV2 2015年12月2日
haohaibo  LV10 2015年12月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友