【问题标题】:Why is this htaccess redirect reporting as a temporary redirect?为什么此 htaccess 重定向报告为临时重定向?
【发布时间】:2018-11-30 00:41:54
【问题描述】:

我正在进行 SEO 审核,并注意到某些页面被报告为临时重定向,而不是永久重定向。我确定这是来自从 HTTP 到 HTTPS 的重定向设置。

这是来自 .htaccess 文件的重定向。

# website www redirect
RewriteEngine On
rewritecond %{http_host} ^example.com
rewriteRule ^(.*) https://www.example.com/$1 [R=301,L]

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

谁能告诉我这是否被错误地实现为 HTTPS 的永久重定向?

【问题讨论】:

    标签: .htaccess ssl redirect web hosting


    【解决方案1】:

    https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_r

    可以使用语法 [R=305] 指定任何有效的 HTTP 响应状态代码,如果未指定,则默认使用 302 状态代码。

    因此,在您的第二个配置块中,[R,L] 中的R 是一个临时重定向(代码302)。如果您想要永久重定向,请将其更改为 R=301,或者更清晰的 R=permanent

    此外,对于不需要mod_rewrite 的简单重定向,只需查看Redirect 指令或其包装器:RedirectTempRedirectPermanent,来自mod_alias 模块(请参阅https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 2016-08-13
      • 2021-12-25
      • 2021-11-17
      • 2013-10-05
      • 2012-08-08
      相关资源
      最近更新 更多