在某些URL上添加SSL可选

时间:2017-03-07 19:18:36

标签: .htaccess ssl apache2 vhosts apache2.4

我正在使用Apache 2作为网络应用。

我想为大多数网址强制使用SSL。例如如果我转到http://example.com/foo,我将被重定向到https://example.com/foo

这很容易使用:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    RewriteEngine on
    RedirectMatch ^(/.*)$ https://example.com$1
</VirtualHost>

但是,我希望SSL对于具有此模式的任何网址都是可选的:

example.com/api/*

原因是我的移动应用程序已经上线并使用网站的http版本,我不想打破它。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用

添加RewriteRule
RewriteCond %{REQUEST_URI} !^/api/