簡體   English   中英

通過.htaccess從HTTPS排除一頁,但將該頁面上的鏈接重定向回HTTPS

[英]Exclude one page from HTTPS via .htaccess, but redirect links on that page back to HTTPS

我正在使用WordPress。 我需要強制所有頁面使用HTTPS,期望一個特定頁面的iframe包含無法替換的不安全內容。

我在.htaccess文件中嘗試了許多不同的配置。 他們中的一些人比其他人工作得更好,但是沒有一個人能完全工作。

我遇到的問題是該站點上的導航菜單使用相對鏈接。 我發現一些選項使我可以在iframe頁面上強制使用HTTP,但是在該頁面上(在iframe之外)單擊的所有導航鏈接都不會重定向回這些頁面的HTTPS版本。

這是我遇到的一個效果不佳的示例。

<IfModule mod_rewrite.c>
RewriteEngine On
# Go to https if not on /iframe/
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/iframe/$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

# Go to http if you are on /iframe/
RewriteCond %{SERVER_PORT} !80 
RewriteCond %{REQUEST_URI} ^/iframe/$ [NC]
RewriteRule ^(.*)$ https//www.example.com/$1 [R=301,L]
</IfModule>

您可以在.htaccess文件中使用以下規則來實現。 這是首先檢查HTTPs是否未打開,否則,它將把除目錄/iframe/以外的所有內容轉發到HTTPs。 第二條規則檢查HTTPs是否打開,如果打開,它將/frame/重定向回HTTP。

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} !^\/(iframe)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]

RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} ^\/(iframe)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

測試之前,請確保清除緩存。

編輯:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/iframe/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} ^/iframe/ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM