在 apache 中,如果我访问 https://example.com,所有图像/链接都是 http://。有没有办法自动重写 html,使其全部为 https://?
我确信我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
Try this:
除非你到处都使用绝对 URL,否则这应该“自动”工作。因此,您只需要检查两件事:
Unless you use absolute URLs everyhwere, this should work "automagically". So you only need to check two things:
<base href="http://something">
您只需链接到
/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 ofhttp://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.
您引用的 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.