簡體   English   中英

如果通過htaccess不存在querystring參數,則將HTTPS重定向到HTTP

[英]Redirect HTTPS to HTTP if querystring parameter is absent via htaccess

只想在缺少以下查詢字符串參數的情況下將HTTPS重定向到HTTP:

https://www.example.com/index.php?p=login
https://www.example.com/index.php?p=signup
https://www.example.com/index.php?p=cart
https://www.example.com/index.php?p=one_page_checkout

也就是說, 除此以外的任何查詢字符串都應從HTTPS重定向到HTTP。 我想確保只有我的結帳路徑是HTTP。

可以簡單地將.htaccessRewriteCondRewriteRule嗎?

將此添加到文檔根目錄中的htaccess文件中,最好在可能已經存在的所有規則之上:

RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)p=(login|signup|cart|one_page_checkout)(&|$)
RewriteCond %{HTTPS} on
RewriteRule ^index\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{QUERY_STRING} (^|&)p=(login|signup|cart|one_page_checkout)(&|$)
RewriteCond %{HTTPS} off
RewriteRule ^index\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

要使其永久重定向,請在方括號R后面添加=301

通過httpd.conf啟用mod_rewrite和.htaccess,然后將此代碼放在DOCUMENT_ROOT目錄下的.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !(^|&)p=(login|signup|cart|one_page_checkout)(&|$) [NC]
RewriteRule ^(index\.php)?$ http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

只需將以下幾行放入您的.htaccess文件中:-

RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

暫無
暫無

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

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