网站http强制https方法

  发布时间:2025-11-04 05:37:05   作者:玩站小弟   我要评论
LAMP或者LNMP集成环境跳转:首先在网站根目录下创建.htaccess文件,网站如果目录下已经有.htaccess文件,强制则用vi或者其他编辑器打开,方法在最下面添加写入如下语句即可RewriteEngine on 网站 RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] Apache服务器:如果需要整站跳转,则在网站的强制配置文件的<Directory>标签内,键入以下内容:RewriteEngine on 方法 RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] 如果对某个目录做https强制跳转,则复制以下代码:RewriteEngine on 网站 RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] Nginx服务器:在配置80端口的文件里面,写入以下内容即可。强制server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root <a target="_blank" href="https://www.kaiyuanyuanma.com/tag/31.html" title="View all posts in html">html</a>; index index.html index.htm; } server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root <a target="_blank" href="https://www.kaiyuanyuanma.com/tag/31.html" title="View all posts in html">html</a>; index index.html index.htm; } server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; } JS跳转:以下方法较适合指定某一个子页单独https,方法如果网页定义了top或者boot文件,网站可以在这个文件里面加入;在需要强制为https的强制页面上加入以下代码进行处理http–>https<script type="text/<a target="_blank" href="https://www.kaiyuanyuanma.com/tag/35.html" title="View all posts in javascript">javascript</a>"> var url = window.location.href; if(url.indexOf("https")<0){ url = url.replace("http:", "https:"); window.location.replace(url); } </script> <script type="text/<a target="_blank" href="https://www.kaiyuanyuanma.com/tag/35.html" title="View all posts in javascript">javascript</a>"> var url = window.location.href; if (url.indexOf("https") < 0) { url = url.replace("http:", "https:"); window.location.replace(url); } </script> <script type="text/javascript"> var url = window.location.href; if (url.indexOf("https") < 0) { url = url.replace("http:", "https:"); window.location.replace(url); } </script> PHP跳转:添加在网站php页面内<?php if($_SERVER["HTTPS"]<>"on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> <?php if ($_SERVER["HTTPS"] <> "on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> <?php if ($_SERVER["HTTPS"] <> "on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> 内容看完了 © 版权声明 1:本网站名称:蜡笔傻新2:本站永久网址:https://labishaxin.com/3:本站部分内容收集于互联网,如果有侵权内容、方法请联系我们删除,网站不妥之处,强制敬请谅解4:本站一切资源不代表本站立场,方法并不代表本站赞同其观点和对其真实性负责5:本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报6:本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。

LAMP或者LNMP集成环境跳转:

首先在网站根目录下创建.htaccess文件,网站如果目录下已经有.htaccess文件 ,强制则用vi或者其他编辑器打开 ,方法在最下面添加写入如下语句即可

RewriteEngine on 网站 RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Apache服务器 :

如果需要整站跳转 ,则在网站的强制配置文件的标签内,键入以下内容:

RewriteEngine on 方法 RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]

如果对某个目录做https强制跳转 ,则复制以下代码:

RewriteEngine on 网站 RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Nginx服务器:

在配置80端口的文件里面,写入以下内容即可。强制

server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; } server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; } server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; }

JS跳转  :

以下方法较适合指定某一个子页单独https,方法如果网页定义了top或者boot文件,网站可以在这个文件里面加入;

在需要强制为https的强制页面上加入以下代码进行处理http–>https

PHP跳转 :

添加在网站php页面内

"on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> "on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> "on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> 内容看完了 © 版权声明 1:本网站名称:蜡笔傻新

2:本站永久网址 :https://labishaxin.com/

3:本站部分内容收集于互联网 ,如果有侵权内容 、方法请联系我们删除,网站不妥之处 ,强制敬请谅解

4:本站一切资源不代表本站立场 ,方法并不代表本站赞同其观点和对其真实性负责

5:本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报

6:本站资源大多存储在云盘  ,如发现链接失效 ,请联系我们我们会第一时间更新

  • Tag:

相关文章

最新评论