301 重定向到除 robots.txt 之外的所有内容

发布于 2024-09-24 11:58:10 字数 389 浏览 0 评论 0原文

我们已将网站移至新域,并希望旧网站的所有页面从搜索引擎中删除。这是相同的网站,相同的内容,只是一个新域,因此搜索引擎由于重复的内容(可能)而花费时间。我们已将 .htaccess 301 从旧站点添加到新站点,如下所示:

redirect 301 / http://new-domain.com/

现在,为了从搜索引擎中删除旧站点,我们将旧站点上的 robots.txt 更改为:

User-agent: *
Disallow: /

问题是,搜索引擎正在获取 robots.txt由于 .htaccess 301 重定向,来自 new-domain.com。

如何限制 robots.txt 的 301 重定向?

We have moved our website to a new domain and want all pages of the old site to get removed from search engines. It's the same site, same content, just a new domain, so search engines are taking time because of duplicate content (maybe). We have added .htaccess 301 from our old site to new site as:

redirect 301 / http://new-domain.com/

Now, to remove our old site from search engines, we changed our robots.txt on the old site as:

User-agent: *
Disallow: /

The problem is, the search engines are fetching robots.txt from the new-domain.com because of .htaccess 301 redirect.

How do I restrict 301 redirect for robots.txt?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白龙吟 2024-10-01 11:58:10

删除 Redirect 指令并尝试此 mod_rewrite 规则:

RewriteEngine on
RewriteRule !^robots\.txt$ http://other.example.com%{REQUEST_URI} [L,R=301]

这将重定向除 /robots.txt 之外的任何请求。

Remove the Redirect directive and try this mod_rewrite rule:

RewriteEngine on
RewriteRule !^robots\.txt$ http://other.example.com%{REQUEST_URI} [L,R=301]

This will redirect any request except /robots.txt.

↘紸啶 2024-10-01 11:58:10

我尝试了不同的配置并花了几个小时,最后我发现这段代码运行良好,希望得到预期的结果
这是禁止搜索引擎的代码。

User-agent: *
Disallow: /

I was trying different configurations and spent hours and finally I found this code which is working well and hope to get the desired results
Here is the code for disallowing search engines.

User-agent: *
Disallow: /
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文