2017-09-12 152 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] 

您将需要当然插入正确的域,但它应该工作。我在我的系统上进行了测试,结果如此。