【问题标题】:Google is not indexing https谷歌没有索引 https
【发布时间】:2021-10-29 00:48:22
【问题描述】:

我用http协议很久了。多年后,我实施了域证书。现在我正在尝试使用 https:// 协议索引该网站,但 Google 仍然索引 http 协议。

我已经尝试了几件事。我在 DirectAdmin 中启用了“使用 https 重定向强制 SSL”选项。

我更改了我的 .htaccess,因此浏览器将每个选项重定向到 https 协议:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RedirectMatch permanent index.php/(.*) https://www.***.com/$1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html) [NC]
RewriteRule ^index\.php$ https://www.***.com/ [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php|html)\ HTTP
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^home\.html$ "https\:\/\/www\.domain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^home$ "https\:\/\/www\.domain\.com\/" [R=301,L]

我创建了一个仅包含 https:// 协议的 sitemap.xml。

在 Google 搜索控制台中,我看到该网站今天已编入索引,并且“Google 选择的规范 URL”仍然是 http 协议。

有人知道我需要做什么来解决这个问题吗?

【问题讨论】:

  • 你有一个canonical 链接元素,它被设置成什么?
  • 是的:<link rel="canonical" href="https://www.example.com" />
  • 我也尝试过删除规范链接元素,但结果是一样的。 https 协议未编入索引。 Google 仍然显示 http 结果
  • “我在 DirectAdmin 中启用了‘使用 https 重定向强制 SSL’选项。” - 这究竟是做什么的?您“切换到 HTTPS”有多久了?您是否在这个帐户上托管多个域?

标签: .htaccess http redirect mod-rewrite https


【解决方案1】:

我更改了我的 .htaccess,因此浏览器将每个选项重定向到 https 协议:

其实你没有。

您根本没有 HTTP 到 HTTPS 的重定向,第一条规则(非 www 到 www 的重定向)专门维护所请求的任何协议(HTTP 或 HTTPS)。

尝试以下两条规则,替换您的第一个(非 www 到 www)规则

# non-www to www (and HTTPS)
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# HTTP to HTTPS (already www)
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

剩下的指令也可以简化...

# Redirect to path-info (removing "index.php")
RewriteRule ^(.+/)?index\.php/(.*) /$1 [R=301,L]

# Remove "index.php" from the end of the URL
RewriteRule ^(.+/)?index\.php$ /$1 [R=301,L]

# Redirect "home" and "home.html" to the document root
RewriteRule ^home(\.html)?$ / [R=301,L]

后面的指令中似乎不需要定位域名,所以我把看似多余的条件去掉了。

我已将删除 index.php 的两条规则简化/简化为单个指令。除非您有一个前端控制器将所有请求路由到index.php,否则您不需要检查THE_REQUEST 的附加条件。 (您发布的指令中没有前端控制器。)

(虽然如果你没有前端控制器,移除和重定向到路径信息的规则有点不合适?)

我已将 mod_alias RedirectMatch 更改为相应的*1 mod_rewrite 规则。 mod_alias 指令在 mod_rewrite 之后处理,尽管配置文件中指令的顺序很明显,因此建议避免混合来自两个模块的重定向以避免意外冲突。

(*1 我还“更正”了这一点,以避免匹配 <anything>index.php 形式的 URL,而不是 <anything>/index.php,我认为这是意图。)

清除浏览器缓存并首先使用 302(临时)重定向进行测试,以避免任何潜在的缓存问题。

我也尝试删除规范链接元素

如果您链接到正确的规范 URL,则不应删除“规范链接元素”,即。 HTTPS + www.

您实际上并没有说明“切换到 HTTPS”之后的时间,但这可能需要一些时间。谷歌自然偏爱 HTTPS,但由于您网站的年龄,您可能会有很多 HTTP 反向链接。将 HTTP 301 重定向到 HTTPS 很重要。

您应该在 GSC 中注册两个属性:HTTP 和 HTTPS,并监控两者的索引状态。

注意:这种性质的问题通常最好在网站管理员堆栈中提出:https://webmasters.stackexchange.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-09
    • 2016-07-11
    • 2014-12-20
    • 1970-01-01
    • 2012-08-19
    • 2017-03-28
    • 2015-01-12
    相关资源
    最近更新 更多