强制所有http流量到https,但一个URL除外

时间:2014-06-04 17:58:42

标签: php .htaccess

我正在将所有流量重定向到我的网站以进行https连接。

但我在使用http协议的API页面遇到问题,因此使用上传API的用户无法上传,因为https正在影响整个网站。我已经尝试了几个htaccess规则,但似乎大多数问题与我需要的相反。

以下是我用来强制所有流量转到https的htaccess规则:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

我们假设网址为http://example.com/uploading-api.php

除了upload-api.php之外,我想在网站上强制使用https。在这种情况下,必须使用https on。

访问其他页面

1 个答案:

答案 0 :(得分:3)

你可以这样做:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule !^uploading-api\.php https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301,NE]

RewriteCond %{HTTPS} on
RewriteRule ^uploading-api\.php http://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301,NE]