[英].htaccess force redirect a rewritten url in htaccess to use https ssl
我想對某些重寫頁面強制使用SSL,以便它們必須使用SSL。
這些網址是:
http://domain.com/signin
http://domain.com/register
我希望他們是:
https://domain.com/signin
https://domain.com/register
這是我當前的.htaccess
:
RewriteEngine on
RewriteRule ^signin$ index.php?&action=showLogin [QSA,L,NC]
RewriteRule ^register$ index.php?&action=showRegister [QSA,L,NC]
我嘗試了以下方法,但未成功:
RewriteEngine on
RewriteRule ^signin$ index.php?&action=showLogin [QSA,L,NC]
RewriteRule ^register$ index.php?&action=showRegister [QSA,L,NC]
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} ^/(signin|register)
RewriteRule (.*) https://domain.com/$1 [R]
內部重寫之前,您需要重定向到https。
使用此代碼:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(signin|register)/?$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteCond %{HTTPS} on
RewriteRule !^(signin|register)/? http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteRule ^signin$ index.php?&action=showLogin [QSA,L,NC]
RewriteRule ^register$ index.php?&action=showRegister [QSA,L,NC]
http://www.besthostratings.com/articles/force-ssl-htaccess.html
有時您可能需要確保用戶通過安全連接瀏覽您的站點。 始終將用戶重定向到安全連接(https://)的簡單方法可以通過包含以下幾行的.htaccess文件來實現:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Please, note that the .htaccess should be located in the web site main folder.
如果您希望對特定文件夾強制使用HTTPS,則可以使用:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]
The .htaccess file should be placed in the folder where you need to force HTTPS.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.