gpt4 book ai didi

.htaccess - 使用 .htaccess 覆盖现有的 "noindex, nofollow"X-Robots-Tag header ?

转载 作者:行者123 更新时间:2023-12-04 04:00:59 24 4
gpt4 key购买 nike

我正在尝试设置 X-Robots-Tag 以允许 Googlebot 为我的网站编制索引。我没有 robots.txt 文件,在我的任何 html 文件中也没有任何与 X-Robots-Tag 相关的元标记。 Apache 服务器正在返回一个 header ,其中 X-Robots-Tag 设置为 "noindex, nofollow"。如何通过编辑 .htaccess 文件取消设置此标记?

这是我在使用 Chrome 插件“Robots Exclusion Checker”时得到的结果:

X-Robots status BLOCKED noindex,nofollow.

Date: Thu, 23 Jul 2020 20:27:46 GMT
Content-Type: text/html
Content-Length: 1272
Connection: keep-alive
Keep-Alive: timeout=30
Server: Apache/2
X-Robots-Tag: noindex, nofollow
Last-Modified: Fri, 09 Mar 2018 19:26:43 GMT
ETag: "ae0-xxxxxxxxxx-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=3600
Expires: Thu, 23 Jul 2020 21:27:46 GMT

我的 .htaccess 文件的内容:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

Header onsuccess unset X-Robots-Tag
Header always set X-Robots-Tag "index,follow"

我尝试将其添加到 .htaccess 文件的底部:

<files *.html>
Header set X-Robots-Tag "index,follow"
</files>

然后我从 Chrome 扩展程序得到了这个响应:

X-Robots BLOCKED noindex,nofollow,index,follow.

(注意它在下面的列表中出现了两次。)

Date: Thu, 23 Jul 2020 20:39:42 GMT
Content-Type: text/html
Content-Length: 1272
Connection: keep-alive
Keep-Alive: timeout=30
Server: Apache/2
X-Robots-Tag: noindex, nofollow
Last-Modified: Fri, 09 Mar 2018 19:26:43 GMT
ETag: "ae0-xxxxxxxxxxxxx-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=3600
Expires: Thu, 23 Jul 2020 21:39:42 GMT
X-Robots-Tag: index,follow

有没有办法删除原来的 X-Robots-tag header 并用新 header 替换?我尝试了 Header unset X-Robots-Tag,但没有成功(仍然显示“BLOCKED noindex,nofollow”)。


解决方案:对我有用的是包含一个 robots.txt 文件并确保所有超链接都以尾部斜杠结尾。似乎没有尾部斜杠,我得到了 301 重定向,其中包括有问题的 noindex,nofollow header 。

最佳答案

My index.html page is very, very simple and only hyperlinks inside the body to other parts of the site.
The site is hosted on ...

如评论中所述,您首先应该确定设置此 header 的来源,而不是试图覆盖(或取消设置)它。这不是 Apache 默认执行的操作,必须在某处显式设置此 header 。

如果您没有设置此 header (在您的服务器端脚本或文件系统路径上的任何 .htaccess 文件中 - 甚至在文档根目录之上),则必须在 vHost/server 配置中设置它。如果您无权访问服务器配置,那么您应该联系您的虚拟主机以查看问题所在。

<files *.html>
Header set X-Robots-Tag "index,follow"
</files>

这通常会“有效”,除非标题先前已在 always 上设置响应头表。在这种情况下,您需要执行相同的操作。例如:

Header always set X-Robots-Tag "index,follow"

你不应该需要 <Files>包装器 - 除非您特别想要针对仅映射到 *.html 的请求文件?我可以想象在每个 请求(例如图像和其他静态资源)上设置“noindex,nofollow” header 。

但是,您不需要明确设置“index,follow”——因为这是搜索引擎执行的默认行为,无论标题是否设置。因此,在这种情况下,您只需要取消设置 header (正如您所建议的那样),但同样,您需要使用 always表头(如果那是表头被设置为开头的表)。例如:

Header always unset X-Robots-Tag

“总是”表的命名可能有点误导,因为上面看起来(对于不经意的读者)标题可能总是未设置(与有时) - 但事实并非如此。有两个单独的响应 header 组/表:“始终”和“onsuccess”(默认)。两者是相互排斥的。不同之处在于“始终”组是始终应用的——即使是在错误和内部重写/子请求时也是如此。默认组不是。

引用:
https://httpd.apache.org/docs/2.4/mod/mod_headers.html#header

关于.htaccess - 使用 .htaccess 覆盖现有的 "noindex, nofollow"X-Robots-Tag header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63062994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com