2017-09-12 153 views
0

我不知道如何解決這個問題。我需要從HTTP重定向到HTTPS,但只在某些情況下:htaccess重寫多個條件

重定向

http://example.com to https://example.com 
http://example.com/any-url to https://example.com/any-url 

鴕鳥政策重定向

http://subdomain1.example.com 
http://subdomain2.example.com 
http://example.com/any-file.xml 

林開啓SSL,但只有我的域名有一個認證,我喜歡保持XML文件不重定向,以避免一些合作伙伴的問題。

任何幫助?

回答

0

此重寫應該工作:

RewriteEngine on 
RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP_HOST} example.com 
RewriteCond %{REQUEST_URI} !\.xml$ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
0

在你的情況,這會工作,假設你的常規HTTP連接端口80:

# If the site is plain HTTP 
RewriteCond %{SERVER_PORT} 80 
# and if the requested filename is not an XML file 
RewriteCond %{REQUEST_FILENAME} !^(.*)\.xml$ 
# and if the URL specifies the request is for the primary domain (not subdomain) 
RewriteCond %{HTTP_HOST} ^example.com$ 
# then rewrite to HTTPS 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] 

您將需要當然插入正確的域,但它應該工作。我在我的系統上進行了測試,結果如此。