簡體   English   中英

htaccess-重定向到https不起作用

[英]htaccess - redirect to https not working

每個: https : //exp-resso.com/blog/post/2011/08/securing-your-expressionengine-website-with-https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond $1 ^(member|account|checkout|system) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

這告訴您的服務器“如果HTTPS已關閉,並且請求以成員OR帳戶OR結帳OR系統(不區分大小寫)開始,請重定向到https://current-domain/current-page ”。 這是鎖定整個子文件夾/模板組的一種很好的簡單方法。

我已將其添加到我的htaccess文件中,如下所示:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond $1 ^(sign-in|sign-up) [NC]
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
</IfModule>

但是,當我轉到http://mydomain.com/sign-in時 ,URL不會更改為https://mydomain.com/sign-in 知道有什么問題嗎?

編輯1:

我的htaccess也有以下內容(刪除“ www”),我想知道兩者是否都可能引起問題?

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

編輯2:

消除過程,原來是造成問題的原因:

<IfModule mod_rewrite.c>
        RewriteEngine On

        # Removes index.php from ExpressionEngine URLs
        RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

當我注釋掉RewriteRule時,https://是強制的。 是什么引起沖突?

嘗試在RewriteRule中放入(登錄|注冊)條件:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(sign-in|sign-up)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=301] 

那這個呢? (如果端口== 80,則重定向)

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} member [OR]
RewriteCond %{REQUEST_URI} account [OR]
RewriteCond %{REQUEST_URI} checkout [OR]
RewriteCond %{REQUEST_URI} system
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

首先,確保重寫在您的服務器上有效,並且htaccess被讀取(例如,通過在每個URL上發出重定向)。

然后使用RewriteCond %{REQUEST_URI} ^/(sign-in|sign-up)代替RewriteCond $1 ^(sign-in|sign-up) [NC]

它有效並且也更容易閱讀

所以你的htaccess應該看起來像這樣

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/(sign-in|sign-up) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

暫無
暫無

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

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