在 apache 中,如果我访问 https://example.com,所有图像/链接都是 http://。有没有办法自动重写 html,使其全部为 https://?

发布于 2024-08-09 09:09:37 字数 329 浏览 4 评论 0原文

我确信我已经在 apache 中看到了一个可以重写 url 的功能,这样你就可以将domain2.com 指向domain1.com,它会动态地将domain1.com 的所有内容重写为domain2.com。

https 有类似的东西吗?

在apache中,如果我转到https://example.com,页面本身是通过https,但所有图像/链接是http://。有没有办法自动重写html,使其全部为https://?

(顺便说一句,它正在运行 zen cart)

I'm sure i've seen a feature in apache that can rewrite urls so you can point domain2.com at domain1.com and it rewrites everything domain1.com to domain2.com on the fly.

is there a similar thing for https?

In apache, if i go to https://example.com, the page itself is over https, but all images/links are http://. Is there way to auto rewrite the html so its all https://?

(it's running zen cart by the way)

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

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

发布评论

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

评论(4

翻身的咸鱼 2024-08-16 09:09:37

试试这个

使用独立于协议的绝对
路径:


如果浏览器正在查看以下页面
SSL 通过 HTTPS,然后它会请求
该资产具有 https 协议,
否则它将使用 HTTP 请求。

这可以防止可怕的“此页面
包含安全和非安全
Items” IE 中的错误消息,保留
您的所有资产请求
相同的协议。

Try this:

Using a protocol-independent absolute
path:

<img src="//domain.com/img/logo.png"/>

If the browser is viewing an page in
SSL through HTTPS, then it'll request
that asset with the https protocol,
otherwise it'll request it with HTTP.

This prevents that awful "This Page
Contains Both Secure and Non-Secure
Items" error message in IE, keeping
all your asset requests within the
same protocol.

我们只是彼此的过ke 2024-08-16 09:09:37

除非你到处都使用绝对 URL,否则这应该“自动”工作。因此,您只需要检查两件事:

  • 使用相对 URL 指向您自己服务器上的资源,并
  • 确保您没有使用

Unless you use absolute URLs everyhwere, this should work "automagically". So you only need to check two things:

  • use relative URLs to point to resources on your own server and
  • make sure you're not using <base href="http://something">
十年九夏 2024-08-16 09:09:37

您只需链接到 /path/to/page.html 而不是 http://example.com/path/to/page.html。这样,如果是 HTTP,则将保持 HTTP,如果是 HTTPS,则将保持 HTTPS。

不过,如果 Zen Cart 将域添加到所有链接,您将需要编辑软件。

You can just link to /path/to/page.html instead of http://example.com/path/to/page.html. That way, if it's HTTP it'll stay HTTP, and if it's HTTPS it'll stay HTTPS.

If Zen Cart is adding the domain to all links, though, you'll need to edit the software.

奢望 2024-08-16 09:09:37

您引用的 apache 模块称为 mod_rewrite,是的,它可以处理您所要求的内容,尽管我同意上述答案,即使用独立于协议的路径是最好的解决方案。

The apache module you referenced is called mod_rewrite, and yes it can handle what you are asking for, although I agree with the above answers that using a protocol independent path is the best solution.

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