首页 > 解决方案 > 谷歌没有索引 https

问题描述

我已经使用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 Search Console 中,我看到该网站今天已编入索引,并且“Google 选择的规范 URL”仍然是 http 协议。

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

标签: .htaccesshttpredirectmod-rewritehttps

解决方案


我更改了 .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我也“更正”了这一点,以避免匹配表单的 URL <anything>index.php,而不是<anything>/index.php,我认为这是意图。)

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

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

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

您实际上并没有说明自从“切换到 HTTPS”以来已经过了多长时间,但这可能需要一些时间。谷歌自然偏爱 HTTPS,但由于您网站的年代久远,您可能会有很多 HTTP 反向链接。将 HTTP 301 重定向到 HTTPS 很重要。

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

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


推荐阅读