【问题标题】:How to redirect HTTP requests to HTTPS如何将 HTTP 请求重定向到 HTTPS
【发布时间】:2013-10-31 05:31:58
【问题描述】:

我想将我的所有 url 从 http 重定向到 https 我可以使用给定的代码这样做。

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ "https\:\/\/www\.domain\.com\/$1" [L,R=301]

但问题是,当我的网址类似于 http://domain.com/admin/users/login 时,它会重定向到 https://www.domain.com/users/login 我如何在 https://www.domain.com/admin/users/login 上重定向它

【问题讨论】:

  • /$1之前的目标网址中添加/admin?
  • /admin 只是一个例子,实际上它的动态变量每次都会变化。这是个问题。
  • 您没有通过放置括号来捕获$1RewriteRule ^.*$ https://www.domain.com/$0 [L,R=301] 适合你。

标签: .htaccess security redirect https http-redirect


【解决方案1】:

试试:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [L,R=301]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 2011-05-04
    • 2016-11-17
    • 1970-01-01
    相关资源
    最近更新 更多