【问题标题】:From http to https - htaccess and URL rewrite - Too many redirect error从 http 到 https - htaccess 和 URL 重写 - 重定向错误太多
【发布时间】:2018-06-21 19:19:57
【问题描述】:

我有一个站点,在 .htaccess 中包含以下工作代码,以获取友好的 URL:

RewriteEngine On
RewriteRule ^([^_]*)_([^_]*)\.html$ /?s=scheda&id=$1&slug=$2 [L]
RewriteRule ^([^/]*)\.html$ /?s=$1 [L]

由于我安装了 SSL 证书,我需要更新我的 .htaccess 以将 http 内容重定向到 https。我找到了这段代码:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

我尝试将它添加到我的 .htaccess 中:

RewriteEngine On
RewriteRule ^([^_]*)_([^_]*)\.html$ /?s=scheda&id=$1&slug=$2 [L]
RewriteRule ^([^/]*)\.html$ /?s=$1 [L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

但我收到“重定向问题过多”错误。

怎么了?

非常感谢。

【问题讨论】:

    标签: .htaccess ssl redirect https url-rewriting


    【解决方案1】:

    此错误表明您正在循环,我只能看到一个可以循环的规则:

    RewriteRule ^([^/]*)\.html$ /?s=$1 [L]
    

    这会将 a.html 重定向到符合相同规则的 ?s=a.html。

    但它也不应该在 http 中工作。你能确认一下吗?

    【讨论】:

    • 感谢您的回复。请考虑以下代码在 http 上正确运行。 RewriteEngine On RewriteRule ^([^_]*)_([^_]*)\.html$ /?s=scheda&id=$1&slug=$2 [L] RewriteRule ^([^/]*)\.html$ /?s=$1 [L] 添加第二部分时出现循环问题:RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    • 你应该把 http -> https 重定向放在第一位。为什么只使用 L 标志而不使用 R,L ? L 以其问题而闻名(httpd.apache.org/docs/2.4/rewrite/flags.html#flag_r)。尝试按照文档的建议添加 END 标志。如果仍然无法正常工作,请将您的日志设置为详细并返回日志(LogLevel alert rewrite:trace3 in httpd.conf)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2018-12-15
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多