时光沉淀

  • 首页
  • 分享
  • 随笔
  • 归档
  • 友链
  • 关于

部署SSL证书后实现http自动重定向https

  • 浪子
  • 2016-11-26
  • 0

在安装证书完成后,要想实现输入域名自动跳转到https,需要通过添加代码才能达到效果。
在你的网站根目录下的.htaccess文件(没有需要创建一个)中添加下面代码然后保存即可:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.<em>)$ <a href="https://imsun.pw/$1">https://imsun.pw/$1</a> [R,L]

你网站的域名替换imsun.pw
如果想指定某一个文件使用https,则添加一下代码(此时.htaccess文件需要放在你指定的文件夹中)

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.</em>)$ <a href="https://www.yourdomainname.com/somefolder/$1">https://www.yourdomainname.com/somefolder/$1</a> [R,L]

© 2023 时光沉淀
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}