SSL 重写重定向 apache2

发布于 2024-10-08 05:30:46 字数 1771 浏览 3 评论 0原文

我有两个虚拟主机设置为服务器上的同一目录。一个监听端口 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 然后我点击

Index 将我带到 < a href="http://localhost/index.html" rel="nofollow">http://localhost/index.html

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

我怎样才能实现这一目标?

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

I have two virtual hosts set to the same directory on the server. One listens on port 80 and the other on 443.

I have 3 files

index.html
secure.html
view.html

Each file has a menu:

<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>

I would like to set redirecting so it meets these conditions:

http://localhost/secure.html - goes to https://localhost/secure.html

http://localhost/index.html - goes to http://localhost/index.html

http://localhost/view.html - goes to http://localhost/view.html

https://localhost/index.html - goes to http://localhost/index.html

https://localhost/view.html - goes to http://localhost/view.html

and when I'm in
https://localhost/secure.html and I click on

Index takes me to http://localhost/index.html

View takes me to http://localhost/view.html

How could I achieve this?

I know I have to put these in .htaccess file but I don't know how to define these confitions,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘曦 2024-10-15 05:30:46

尝试这两个规则:

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|...)$ 等模式。

Try these two rules:

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]

If you have more than this single file, just extend the pattern like ^/(secure\.html|…)$.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文