已安装ssl安全协议证书的网站,通过.htaccess设置,实现全站http链接301重定向到https的方法

很多已经安装ssl安全协议证书的网站会发现,http的链接和https的链接都有效,如果要用户访问任何链接的时候都强制跳转到https协议的url上,linux主机用户可以通过修改根目录下的.htaccess文件来设置。方法如下:

在.htaccess中

RewriteEngine on 
RewriteBase /

代码下添加如下两行代码:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

保存后再访问网站,就会发现访问站点任意链接,都强制跳转到https协议的URL了。

 

 

 

关于博主
骨灰级博客玩家
国内第一批90后网站站长/程序员
做过七年前端讲师
目前从事锦鲤观赏鱼电商行业
鱼贝贝锦鲤创始人
文章列表
1
神坑React Native之react-native-vector-icons组件报错While resolving module `react-native-vector-icons/MaterialIcons`, the Haste package `react-native-vector-icons` was found. However the module `MaterialIcons` could not be found within the package的解决方案
神坑React Native之react-native-vector-icons组件报错While resolving module `react-native-vector-icons/MaterialIcons`, the Haste package `react-native-vector-icons` was found. However the module `MaterialIcons` could not be found within the package的解决方案
2
老孙IT数码站 低调上线
老孙IT数码站 低调上线
3
一代枭雄谢幕!Firefox火狐更新到57版本,Firebug插件退出历史舞台
一代枭雄谢幕!Firefox火狐更新到57版本,Firebug插件退出历史舞台
4
神坑react native之unable to load script from assets 'index.android.bundle'报错的解决方法
神坑react native之unable to load script from assets 'index.android.bundle'报错的解决方法
5
同志,快醒醒,客户说不改需求了!
同志,快醒醒,客户说不改需求了!
最新评论
比比拉布
比比拉布
5月7日
太感谢了!!!!!!找了这么多的教程,只有你点出来了关键点——设计视图!!!!
Jake
Jake
3月7日
Halo 啊~麻烦更新下我的博客地址,原名:Jing Blog。麻烦更新如下: Jake Blog(后缀可以省略,也可以保留,看哪个风格适合) 网址:htt
评论于关于博主