2013-05-17 63 views
0

我試圖將所有流量重定向到HTTP,除非它是我們的結帳過程,在這種情況下,我試圖將其重定向到HTTPS。htaccess - 將所有頁面除結帳外重定向到HTTP非SSL

我有一個Rackspace雲網站設置,但是下面看起來沒有工作。有什麼我在做下面的不正確?

謝謝!

# Use PHP5 Single php.ini as default 
AddHandler application/x-httpd-php5s .php 

RewriteEngine On 
RewriteBase/

#redirect to www 
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

#redirect all https traffic to http, unless it is pointed at checkout 
RewriteCond %{HTTP:X-Forwarded-SSL} on 
RewriteCond %{REQUEST_URI} !^/checkout/?.*$ 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

#redirect all http traffic to https, if it is pointed at /checkout 
RewriteCond %{HTTP:X-Forwarded-SSL} off 
RewriteCond %{REQUEST_URI} ^/checkout/?.*$ 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 

回答

0
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L] 

#Force NON-SSL on a non-checkout directories 
RewriteCond %{ENV:HTTPS} on [NC] 
RewriteCond %{REQUEST_URI} !^/DIRECTORY/?.*$ 
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L] 

#Force SSL on a specific directory 
RewriteCond %{ENV:HTTPS} !on [NC] 
RewriteRule ^DIRECTORY/(.*)$ https://www.example.com/DIRECTORY/$1 [R,L] 
0

另一種方式:

RewriteCond %{HTTPS} !=on 
# change user|cart|admin to folders you want SSL on. 
RewriteRule ^/?(user|cart|admin) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond %{HTTPS} !=off 
# change content|category to folders you want SSL off. 
RewriteRule ^/?(content|category) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
0

使用此

#redirect all http traffic to https, if it is pointed at /checkout  
    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteCond %{REQUEST_URI} checkout|login 
    RewriteCond %{HTTPS} off 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 
相關問題