【问题标题】:SSL rewrite redirection apache2SSL重写重定向apache2
【发布时间】:2011-05-25 22:41:19
【问题描述】:

我有两个虚拟主机设置到服务器上的同一目录。一个监听 80 端口,另一个监听 443。

我有 3 个文件

index.html
secure.html
view.html

每个文件都有一个菜单:

<ul>
<li><a href="index.html">Index</a></li>
<li><a href="secure.html">secure</a></li>
<li><a href="view.html">view</a></li>
</ul>

我想设置重定向,使其满足以下条件:

http://localhost/secure.html - 转到https://localhost/secure.html

http://localhost/index.html - 转到http://localhost/index.html

http://localhost/view.html - 转到http://localhost/view.html

https://localhost/index.html - 转到http://localhost/index.html

https://localhost/view.html - 转到http://localhost/view.html

当我在
https://localhost/secure.html 并点击

索引将我带到http://localhost/index.html

查看将我带到http://localhost/view.html

我怎样才能做到这一点?

我知道我必须将这些放在 .htaccess 文件中,但我不知道如何定义这些条件,

【问题讨论】:

标签: mod-rewrite ssl redirect https apache2


【解决方案1】:

试试这两条规则:

RewriteCond %{HTTPS} !=on
RewriteRule ^/secure\.html$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} =on
RewriteRule !^/secure\.html$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

如果您有多个文件,只需像 ^/(secure\.html|…)$ 这样扩展模式即可。

【讨论】:

    猜你喜欢
    • 2016-01-26
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 2016-12-20
    • 2016-05-11
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多