2017-09-13 130 views
0

我希望所有人都強制重定向到https,但不在特定頁面上當前我有這個.htaccess文件:如何將所有重定向到ssl和index.php但不是ssl,但重定向到特定頁面上的index.php

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] 

我希望所有重定向到HTTPS,但強制HTTP特定頁面上: /exchage

什麼代碼,我需要把我的.htaccess文件來實現這個功能?謝謝。

回答

1

如何向HTTPS重定向添加另一個條件以檢查路徑是否不以exchange開頭? (我假設你拼錯可置換歲)

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/exchange 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_URI} ^/exchange 
RewriteCond %{HTTPS} on 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] 

一旦你更新你的.htaccess文件,請重新啓動瀏覽器。否則,如果之前看到URL使用https,它可能會強制https。

+0

交換頁面仍然轉到https。 :( –

+0

我剛剛更新了..你能再試一次嗎? –

+0

我試了一遍,但問題仍然存在:( –

0

我用這段代碼解決了這個問題。

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteCond %{THE_REQUEST} !/exchange 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTPS} on 
RewriteCond %{THE_REQUEST} /exchange 
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] 

花了我近3個小時纔出來這段代碼。

+0

很酷,這適用於你。只需注意:這將觸發http/https規則,如果URL _contains_'/ exchange' ...例如'/ anything/exchange/whatever /'也將被強制爲http。 –

+0

我更新它不會觸發該問題。 –

相關問題