當前位置:首頁 » 編程語言 » php跳轉https

php跳轉https

發布時間: 2022-05-15 19:09:20

『壹』 如何設置http到https的自動跳轉

一、Apache伺服器

我們需要找到Apache的配置文件httpd.conf,然後添加以下代碼:

RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]

以上代碼是針對整站進行跳轉,如果只需要跳轉某個目錄,則添加代碼:

RewriteEngine on

RewriteBase /yourfolder

RewriteCond %{SERVER_PORT} !^443$

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;

}

三、Tomcat伺服器

這是三種伺服器裡面相對比較麻煩的,不過一步一步來,也是可以實現的。

首先,我們需要在伺服器根目錄下找到conf這個目錄,找到其中server.xml文件這個文件,修改裡面的redirectPort值為443,默認值一般為8443。

然後,還是在這個目錄下找到web.xml文件,在尾部添加代碼

<security-constraint>

<display-name>Auth</display-name>

<web-resource-collection>

<web-resource-name>Protected Area</web-resource-name>

<url-pattern>/user/*</url-pattern>

<url-pattern>/main/index</url-pattern>

</web-resource-collection>

<user-data-constraint>

<description>SSL required</description>

<transport-guarantee>CONFIDENTIAL</transport-guarantee>

</user-data-constraint>

</security-constraint>

如果用戶遇到的問題不能解決,可通過wosign官網客服尋求幫助,wosign可提供免費一對一的ssl證書技術部署支持網頁鏈接,免除後顧之憂。

『貳』 php跳轉到指定網址

<?php
function redirect($url)
{
if(headers_sent()) {
return false;
}
if(substr($url, 0, 4) != 'http') {
$schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
$host = strlen($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$url = "$schema://$host$to";
}

header("HTTP/1.1 301 Moved Permanently");
// header("HTTP/1.1 302 Found")
// header("HTTP/1.1 303 See Other")
header("Location: $url");

exit();
}

$url = $_REQUEST['url'];
redirect($url);
?>

『叄』 php頁面帶參數跳轉求助

你好,你這個只是網址跳轉 !只需修改訪問網址即可,不需修改代碼

『肆』 JS或PHP實現獲取https協議下上一頁URL

RFC 15.1.3 Encoding Sensitive Information in URI』s 規定:
由HTTPS跳轉到HTTP時不允許發送REFERER頭。

解決方法是把你的網站也成HTTPS的。

參考資料:http://blog.ailms.me/2013/06/24/https-insecure-link-lost-referer-header.html

『伍』 http怎麼做自動跳轉https

首先需要部署好HTTPS證書的伺服器,以下是幾種版本的跳轉方法:

一、APache 版本

1、如果需要整站跳轉,則在網站的配置文件的<Directory>標簽內,鍵入以下內容:

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

2、如果對某個目錄做https強制跳轉,則復制以下代碼:

RewriteEngine onRewriteBase /yourfolderRewriteCond %{SERVER_PORT} !^443$#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

3、如果只需要對某個網頁進行https跳轉,可以使用redirect 301來做跳轉!redirect 301/你的網頁 https://你的主機+網頁

二、Nginx版本

在配置80埠的文件裡面,寫入以下內容即可。

server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent;

location / { root html; index index.html index.htm; }

三、IIS 版本

使用url重定向實現全站跳轉。在此之前,請檢查網站根目錄是否有web.config文件,如有,請先備份這里的web.config文件,因為以下的配置可能會和web.config裡面跳轉沖突。

  1. 選擇需要實現跳轉功能的網站,雙擊「URL重寫」,選擇如下圖「添加規則」。

  2. 在彈出的對話框選擇空白規則,點擊確定。

  3. 根據以下截圖配置新的規則,紅色框框為需要配置或注意的選項。

  4. 展開條件選項,點擊添加按鈕,添加如下圖條件,然後點擊確定。

  5. 再次按下圖提示,添加條件,點擊確定。

  6. 選擇執行操作類型。

  7. 填寫完畢,點擊右上角應用,應用此規則。

  8. 最後確定完成所有設定,實際上上面的文件是改變了網站根目錄web.config的配置文件內容。

以上配置文件內容如下,可以比對

<rule name="Redirect to https"stopProcessing="true">

<match url="(.*)" />

<conditions>

<add input="{HTTPS}" pattern="^OFF$" />

<add input="{HTTPS_HOST}" pattern="^(localhost)"negate="true" />

</conditions>

<action type="Redirect"url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>

</rule>

四、TOMCAT 版本

1、在conf目錄下的server.xml文件中找到以下配置,修改redirectPort參數值為"443",默認是「8443」.

<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />

2、在conf目錄下的web.xml文件內容<web-app>……</web-app>中增加以下配置

<web-app>.........<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></web-app>

五、單獨頁面通用代碼段:以下方法較適合指定某一個子頁單獨https在需要強制為https的頁面上加入以下代碼進行處理http-->https

<script type="text/javascript"> var url = window.location.href; if (url.indexOf("https") < 0) { url = url.replace("http:", "https:"); window.location.replace(url); }</script>

六、在需要強制為http的頁面上加入以下代碼進行處理https-->http

<script language="JavaScript" type="text/JavaScript">function redirect(){ var loc = location.href.split(':'); if(loc[0]=='https') { location.href='http:'+loc[1]; }} onload=redirect </script>

七、PHP頁面跳轉:添加在網站php頁面內

if ($_SERVER["HTTPS"] <> "on") { $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); }

『陸』 thinkphp .htaccess跳轉http到https

.htaccess文件代碼 deny from all Redirect permanent /index.php / order deny,allow 或參考ThinkPHP3.0完全開發手冊 16.2 隱藏index.php

『柒』 如何讓http跳轉到https

如何設置http自動跳轉到https?apache環境下,配置好https後,需要設置url重定向規則,使網站頁面的http訪問都自動轉到https訪問。
1、先打開url重定向支持
1)打開Apache/conf/httpd.conf,找到 #LoadMole rewrite_mole moles/mod_rewrite.so 去掉#號。
2)找到你網站目錄的段,比如我的網站目錄是c:/www,找到
www」>


修改其中的 AllowOverride None 為 AllowOverride All3)重啟apache服務2、設置重定向規則
1)在你網站目錄下放一個.htaccess文件。windows環境下,不能把文件直接改名為.htaccess,會提示你必須輸入文件名。所以我們先新建一個「新建文本文檔.txt」文檔,記事本打開,選擇另存為,保存類型選擇「所有文件(*.*)」,文件名輸入「.htaccess」,保存。這樣便生成了一個.htaccess文件。

2)編輯器打開.htaccess文件,寫入如下規則:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/tz.php
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]

解釋:
%{SERVER_PORT} —— 訪問埠
%{REQUEST_URI} —— 比如如果url是 http://localhost/tz.php,則是指 /tz.php
%{SERVER_NAME} —— 比如如果url是 http://localhost/tz.php,則是指 localhost

以上規則的意思是,如果訪問的url的埠不是443,且訪問頁面不是tz.php,則應用RewriteRule這條規則。這樣便實現了:訪問了
http://localhost/index.php 或者 http://localhost/admin/index.php
等頁面的時候會自動跳轉到 https://localhost/index.php 或者
https://localhost/admin/index.php,但是訪問 http://localhost/tz.php
的時候就不會做任何跳轉,也就是說 http://localhost/tz.php 和 https://localhost/tz.php
兩個地址都可以訪問。

『捌』 zblogphp怎麼設置https跳轉到帶www

1.根據IIS版本備份以下文件:IIS6.0路徑:C:WINDOWSHelpiisHelpcommon403-4.htmIIS7.0以上路徑:C:inetpubcusterrzh-CN403.htm。2.把以下內容全部拷貝替換(403-4或403)裡面所有內容,保存即可

『玖』 http怎麼自動跳轉https

APache 版本

如果需要整站跳轉,則在網站的配置文件的<Directory>標簽內,鍵入以下內容:
1.RewriteEngine on
2.RewriteCond %{SERVER_PORT} !^443$
3.RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R=301]
如果對某個目錄做https強制跳轉,則復制以下代碼:
1.RewriteEngine on
2.RewriteBase /yourfolder
3.RewriteCond %{SERVER_PORT} !^443$
4.#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
5.RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
如果只需要對某個網頁進行https跳轉,可以使用redirect 301來做跳轉!redirect 301 /你的網頁 https://你的主機+網頁

Nginx版本

在配置80埠的文件裡面,寫入以下內容即可。
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
}
IIS 版本

IIs中實現Http自動轉換到Https方法介紹 (403跳轉對SEO有一定影響)
1、根據IIS版本備份以下文件:
IIS6.0 路徑:C:\WINDOWS\Help\iisHelp\common\403-4.htm
IIS7.0以上 路徑:C:\inetpub\custerr\zh-CN\403.htm

2、把以下內容全部拷貝替換(403-4或403)裡面所有內容,保存即可
<HTML><HEAD><TITLE>該頁必須通過安全通道查看</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=GB2312">
</HEAD><BODY>
<script type="text/javascript">
var url = window.location.href;
if (url.indexOf("https") < 0) {
url = url.replace("http:", "https:");
window.location.replace(url);
}
</script>
</BODY></HTML>
注釋:IIS6中,站點屬性-》目錄安全性-》編輯中把「要求安全通道(SSL)」勾選上即可。
IIS7、8中,SSL設置-》把「要求SSL」勾選即可。

TOMCAT 版本

1、在conf目錄下的server.xml文件中找到以下配置,修改redirectPort參數值為"443",默認是「8443」.
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
2、在conf目錄下的web.xml文件內容<web-app>……</web-app>中增加以下配置。
<web-app>
.........
<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>
</web-app>
單獨頁面通用代碼段:以下方法較適合指定某一個子頁單獨https
在需要強制為https的頁面上加入以下代碼進行處理http-->https
<script type="text/javascript">
var url = window.location.href;
if (url.indexOf("https") < 0) {
url = url.replace("http:", "https:");
window.location.replace(url);
}
</script>
在需要強制為http的頁面上加入以下代碼進行處理
https-->http
<script language="JavaScript" type="text/JavaScript">
function redirect()
{
var loc = location.href.split(':');
if(loc[0]=='https')
{
location.href='http:'+loc[1];
}
}
onload=redirect
</script>
PHP頁面跳轉:添加在網站php頁面內
if ($_SERVER["HTTPS"] <> "on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
http跳轉https的方法較多,以上僅供參考,資料鏈接:(https://bbs.wosign.com/thread-46-1-1.html)。

熱點內容
頁面置換演算法實驗報告 發布:2024-05-08 23:51:08 瀏覽:983
十秒編程 發布:2024-05-08 23:34:04 瀏覽:848
輸入源程序後如何編譯 發布:2024-05-08 23:23:36 瀏覽:536
我的世界基岩版練習pvp伺服器 發布:2024-05-08 23:20:23 瀏覽:978
phpmanual 發布:2024-05-08 23:19:50 瀏覽:297
如何登錄不知道密碼的wifi網 發布:2024-05-08 23:09:42 瀏覽:994
java速學 發布:2024-05-08 23:08:43 瀏覽:749
愛心代碼的編譯器 發布:2024-05-08 22:47:08 瀏覽:344
沖突資料庫 發布:2024-05-08 22:47:02 瀏覽:426
c語言雙重性 發布:2024-05-08 22:40:57 瀏覽:439