.htaccess允许通过HTTPS或HTTP访问一个URL

时间:2017-02-13 09:13:57

标签: apache .htaccess

我在.htaccess中有一个重写规则,将我们的网站重定向到HTTPS

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我需要保留一个网址,以便同时使用HTTP和HTTPS(http://www.myhost.com/apihttps://www.myhost.com/api)。我如何修改上面的代码

1 个答案:

答案 0 :(得分:1)

尝试以下规则,

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/support/registration_service
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

以上规则不包括要强制为https的uri /api,因此您可以将www.myhost.com/api用于这两种方案。