2013-02-21 104 views
0

我有这个网址http://www.mysite.com/checkout/payment,好吧,我创建了一个文件htaccess来重定向此页面,当URL与“checkout/payment”不同时,URL变成普通的http。使用HTACCESS将特定页面重定向到HTTPS

但始终有问题发生,资产(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] 
+0

我想你最好改变网址,这些资源,以便它们使用相对URL,例如,而不是''然后使用''。或者注入合适的协议(http/https)。 – kjetilh 2013-02-21 19:57:38

回答

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] 
相关问题