簡體   English   中英

htaccess重定向到https以獲取已重寫的URL

[英]htaccess redirect to https for an already Re-Written URL

這是我的htaccess

Options +FollowSymLinks
RewriteEngine On

# redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# redirect to HTTPs for register
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} register
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

# don't do anything for images/css/js etc
RewriteRule \.(gif|jpe?g|png|css|js|woff|map)$ - [NC,L]

# redirect to HTTP for all other pages
RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !register
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [PT,L]

我有一個注冊頁面,其URL類似於hxxp://www.example.com/index.php?register ,並且htaccess正確重定向到HTTPS。

現在,我還希望我的購買頁面( hxxpp://www.example.com/buy重定向到HTTPS 此頁面的真實URL是hxxp://www.example.com/index.php?

請為我提供有關如何修改htaccess規則以解決此需求的建議。

您可以在https規則中使用正則表達式替代:

# redirect to HTTPs for register
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /(register|buy)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]

確保這是我們htaccess中的首要規則

暫無
暫無

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

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