2013-02-21 85 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] 
相關問題