2016-06-09 63 views
1

如何重定向HTTP到HTTPS排除特定的網址是什麼?的.htaccess - HTTP重定向到https排除特定的URL

http://www.example.com/* => https://www.example.com/* 
http://www.example.com/nonssl/* => http://www.example.com/nonssl/* 

所以我提出以下這個.htaccess文件:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} !^/nonssl/ 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

但是,當我去http://www.example.com/nonssl/testfunc,它進入https://www.example.com/index.php/nonssl/testfunc

在此先感謝。

+0

是/ nossl一個存在的目錄? – starkeen

+0

不,我使用codeigniter製作了這個網站。這是一個控制器名稱。 – Zuiche

回答

0

對於這個問題,我沒有找到正確的方法,只是描述了所有的服務,從HTTP重定向到https。

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} ^/$ [OR] 
RewriteCond %{REQUEST_URI} ^/test [OR] 
RewriteCond %{REQUEST_URI} ^/test1 [OR] 
RewriteCond %{REQUEST_URI} ^/test2 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|images|css|fonts|js|robots\.txt) 
RewriteRule ^(.*)$ index.php?/$1 [L] 

我知道它只是不推薦的方式。如果誰可以解決這個問題,只需連接我。 謝謝。

+0

它醜,但工作! –