2016-12-07 143 views
1

我需要將我網站的所有頁面從https重定向到http,但sign-in頁面除外。我想如果有人試圖通過http瀏覽sign-in頁面,它應該被重定向到https。我的網站是在drupal 7下開發的。但是,我在.htaccess中寫了一些條件,但沒有運氣。我所做的是:將https重定向到http,除了登錄頁面

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

通過上面的代碼中的所有頁面重定向到httpshttpsign-in沒有得到例外。

回答

1

保持這2個重定向規則,在你的.htaccess的頂部:

RewriteEngine On 

# redirect anything except /sign-in to http 
RewriteCond %{HTTPS} on 
RewriteCond %{THE_REQUEST} !/sign-in [NC] 
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 

# redirect /sign-in to https 
RewriteCond %{HTTPS} off 
RewriteCond %{THE_REQUEST} /sign-in [NC] 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
+0

它不起作用。我不明白爲什麼第二個條件不起作用... – StreetCoder

+1

感謝它幫助我 – StreetCoder

+0

如果我這樣做,出於某種原因,我的字體通過https加載(在http登錄),我得到CORS錯誤。有任何想法嗎? –

0

嘗試這樣的事情

RewriteCond %{HTTPS} off 
    RewriteCond %{REQUEST_URI} !^/sign-in\.php$ [NC] 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA] 

    RewriteCond %{HTTPS} on 
    RewriteRule ^(sign-in\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA] 
+0

沒有運氣我的朋友...它重定向到所有頁面通過'http: // domain.name/index.php'。知道我在做什麼錯了 – StreetCoder

+0

我已經更新了我的答案。如果可能的話,請嘗試這個。 –

+0

現在一切都重定向到「https」。 – StreetCoder