htaccess - 将除checkout之外的所有页面重定向到HTTP非SSL

时间:2013-05-17 18:45:39

标签: .htaccess rackspace-cloud rackspace

我正在尝试将所有流量重定向到HTTP,除非是我们的结帐流程,在这种情况下我正在尝试将其重定向到HTTPS。

我有Rackspace Cloud Sites设置但是下面似乎没有工作。在下面有什么我做错了吗?

谢谢!

# 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]

3 个答案:

答案 0 :(得分: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]

答案 1 :(得分: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]

答案 2 :(得分: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]