【问题标题】:How to redirect from http to https..? [closed]如何从 http 重定向到 https ..? [关闭]
【发布时间】:2013-12-30 16:54:55
【问题描述】:

在不硬编码任何值的情况下从 http 重定向到 https 的最佳方式是什么?

我已经尝试在代码中执行此操作,但在服务器端执行此操作可能是更好的方法吗?

【问题讨论】:

  • 你的意思是来自HttpServletResponseredirect()方法?
  • 我想我更愿意在 Apache 端做这件事,但知道如何将 HttpServletResponse 从 http 重定向()到 https 而不硬编码任何值仍然会很有趣..?

标签: java apache rest servlets


【解决方案1】:

假设你的意思是在 Apache 中,你的虚拟主机应该是这样的:

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/
</VirtualHost >

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost >

如果您正在考虑使用 mod_rewrite:

如果同一范围内有其他 RewriteRule 指令,则使用 RewriteRule 执行此任务可能是合适的。这是因为,当 Redirect 和 RewriteRule 指令在同一个范围内时,无论配置文件中出现的顺序如何,RewriteRule 指令都会先运行

来源:http://httpd.apache.org/docs/trunk/rewrite/avoid.html

【讨论】:

  • 您写道RewriteRule 可能合适,但从链接文章的标题看来您的意思是说不合适。我可能是错的。你能澄清一下吗?
  • 我的意思不是说它似乎不是最好的选择,除非您已经在该虚拟主机中将 mod_rewrite 用于其他目的。
  • 看起来像工作示例..
猜你喜欢
  • 2013-12-22
  • 1970-01-01
  • 2012-11-19
  • 1970-01-01
  • 2016-09-02
  • 1970-01-01
  • 2013-12-03
  • 2019-09-10
  • 2017-10-06
相关资源
最近更新 更多