使用HTACCESS将特定页面重定向到HTTPS

时间:2013-02-21 17:43:46

标签: apache .htaccess http ssl https

我有这个网址http://www.mysite.com/checkout/payment,我创建了一个文件htaccess来重定向此页面,当网址与“结账/付款”不同时,网址变为普通的http。

但是一直出现问题,资产(JS,CSS,JPG,PNG)总是被重定向到正常的HTTP,我是如何解决这个问题的?

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(checkout/pay)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (checkout/pay)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

1 个答案:

答案 0 :(得分:0)

请尝试以下规则:

# Redirect checkout pay(ment) pages to https 
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/checkout/pay [NC]
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# Redirects all resources where the http referer field matches the checkout payment page.
# Weirdly enough I can't seem to use any server variables in the http referer regex. Please change it to match your host.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_REFERER} ^https://www.mysite.com/checkout/pay [NC]
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]