我正在使用 WordPress,我們有一個不是 WordPress 目錄 /images 的目錄,我們需要這個目錄是 HTTP,只有其他所有內容都應該強制為 HTTPS。
在 WordPress 設定中,我們將域設定為 HTTP

在.htaccess檔案中,我們有以下內容。
我似乎無法讓它發揮作用。如果有幫助的話,我們的主機是 cloudways
# This file was updated by Duplicator on 2018-09-10 16:52:27. See .htaccess.orig for the original .htaccess file.
# Please note that other plugins and resources write to this file. If the time-stamp above is different
# than the current time-stamp on the file system then another resource has updated this file.
# Duplicator only writes to this file once during the install process while running the installer.php file.
#RewriteEngine On
#RewriteCond %{HTTP:X-Forwarded-SSL} !on
#RewriteCond %{REQUEST_URI} ^\/(images)
#RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
#RewriteCond %{HTTP:X-Forwarded-SSL} =on
#RewriteCond %{REQUEST_URI} !^\/(images)
#RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# MalCare WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END MalCare WAF
uj5u.com熱心網友回復:
在 wordpress 設定中,我們將域設定為 http
如果您想在除“WordPress 之外”的一個目錄之外的任何地方強制使用 HTTPS,那么 WP 儀表板中的“WordPress 地址”和“站點地址”都應設定為 HTTPS,而不是 HTTP。
#RewriteCond %{HTTP:X-Forwarded-SSL} !on #RewriteCond %{REQUEST_URI} ^\/(images) #RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301] #RewriteCond %{HTTP:X-Forwarded-SSL} =on #RewriteCond %{REQUEST_URI} !^\/(images) #RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301] RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
在根.htaccess檔案中,您可以在任何地方重定向到 HTTPS ,但如果/images/請求目錄(應保留為 HTTP的目錄),則例外以排除進一步處理。
例如:
# Prevent further processing if the "/images" directory is requested
RewriteRule ^images($|/) - [L]
# Redirect everything else to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
:
無需重復該RewriteEngine On指令,因為這已經出現在檔案的后面(在 WP 部分)。
確保在測驗之前清除瀏覽器快取并使用 302(臨時)重定向進行測驗以避免快取問題。
這假設 SSL 證書安裝在您的應用程式服務器上,并且您沒有使用可能管理 SSL 連接的代理/CDN/負載平衡器。
更新:由于上述仍然導致重定向回圈,因此您可能位于管理 SSL 連接的某種代理服務器(CloudWays - 您的網路主機 - 或者可能是 Cloudflare)后面。針對第二條規則(HTTP 到 HTTPS 重定向)嘗試以下操作:
# Redirect everything else to HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/371380.html
