【问题标题】:Redirecting http to https via .htaccess通过 .htaccess 将 http 重定向到 https
【发布时间】:2016-12-16 17:57:42
【问题描述】:

目前,我在论坛站点的 .htaccess 文件中有以下内容。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^/?$ http://example.com/forums/ [L,R=301]

它非常适合将 (http)://example.com、www.example.com、(http)://www.example.com 等所有内容重定向到 example.com/forums,这正是我想要的.

我现在希望将所有内容重定向到 (https)://example.com/forums,但在使用现有链接(例如 example.com/forums/stuff)时遇到了问题。

我只能让example.com重定向到https://example.com/forums,任何直接链接,例如example.com/forums/stuff等都不会重定向到https版本,有什么想法吗?

【问题讨论】:

标签: .htaccess redirect mod-rewrite


【解决方案1】:

您需要 2 个重定向规则。一条规则将登录页面重定向到论坛页面,另一条规则将 http -> https 重定向:

RewriteEngine On

# redirect landing page to /forums/
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com [NC]
RewriteRule ^/?$ https://%{HTTP_HOST}/forums/ [L,R=301]

# redirect http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-08
  • 2012-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
相关资源
最近更新 更多