在某些 URL 上添加 SSL 可选
Add SSL optional on some URLs
我正在使用 Apache 2 作为 Web 应用程序。
我想对大多数 URL 强制使用 SSL。例如如果我转到 http://example.com/foo
,我将被重定向到 https://example.com/foo
。
这很容易使用:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine on
RedirectMatch ^(/.*)$ https://example.com
</VirtualHost>
但是,我希望 SSL 对于具有此模式的任何 url 都是可选的:
example.com/api/*
原因是我的移动应用程序已经上线并使用网站的 http 版本,我不想破坏它。
我该怎么做?
在 RewriteRule 之前加上
RewriteCond %{REQUEST_URI} !^/api/
我正在使用 Apache 2 作为 Web 应用程序。
我想对大多数 URL 强制使用 SSL。例如如果我转到 http://example.com/foo
,我将被重定向到 https://example.com/foo
。
这很容易使用:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine on
RedirectMatch ^(/.*)$ https://example.com
</VirtualHost>
但是,我希望 SSL 对于具有此模式的任何 url 都是可选的:
example.com/api/*
原因是我的移动应用程序已经上线并使用网站的 http 版本,我不想破坏它。
我该怎么做?
在 RewriteRule 之前加上
RewriteCond %{REQUEST_URI} !^/api/