【问题标题】:Using htaccess to redirect correctly使用 htaccess 正确重定向
【发布时间】:2016-03-23 14:26:37
【问题描述】:

我现在在我的项目中使用robots.txtsitemap.xml.htaccess,如果我在 Google 网站管理员工具中提交它们,我的 sitemap.xml 网址会出现访问错误。

robots.txt

User-Agent: *
Disallow:

sitemap.xml

<url>
  <loc>http://www.example.de/</loc>
  <changefreq>daily</changefreq>
</url>
<url>
  <loc>http://www.example.de/blog/article/</loc>
  <changefreq>daily</changefreq>
</url>
<url>
  <loc>http://www.exampe.de/blog/article/example-article</loc>
  <changefreq>daily</changefreq>
</url>

.htaccess

RewriteRule ^(.*)blog/article/$ $1article.php
RewriteRule ^(.*)blog/article/example-article$ $1blog/example-article.php

我的文件夹结构:

├───blog
│   └─── example-article.php
├─── sitemap.xml
├─── robots.txt
├─── .htaccess
├─── article.php
├─── ...

谷歌网站管理员工具说:

http://www.example.de/blog/article/
http://www.example.de/blog/article/example-article

被 robots.txt 阻止,这是不可能的,因为我允许抓取所有内容。

我的错误在哪里?

【问题讨论】:

  • 可能是因为您的 robots.txt 阻止了它。您的 robots.txt 看起来不正确。
  • 是的,它被 robots.txt 阻止了。但是错误到底在哪里?我不能在机器人中使用 mod_rewrited 网址吗?因为我希望它们像那样被索引。

标签: .htaccess mod-rewrite sitemap robots.txt google-crawlers


【解决方案1】:

使用:robots.txt

User-Agent: *
Disallow: /only_folder_name_you_disallow/

你不能使用Allow

还要注意,在 User-agent 或 Disallow 行中不支持通配符和正则表达式。 User-agent 字段中的“*”是一个特殊值,意思是“任何机器人”。具体来说,您不能使用“User-agent: bot”、“Disallow: /tmp/*”或“Disallow: *.gif”之类的行。 http://www.robotstxt.org/robotstxt.html

【讨论】:

  • 感谢您的回答。我会试试。什么原因,我不能使用“允许”?我经常看到这种情况。还是在我的情况下它不起作用?
  • 我出于测试目的修改了 robots.txt 以不限制任何内容: User-Agent: * Disallow: 我得到同样的错误,所以问题不在于 robots.txt、.htaccess 或 sitemap.xml错了,但我打赌.htaccess。看到错误原因了吗?
  • “允许”不在机器人排除协议中。即使一些机器人使用它。但是允许一个文件夹,然后全部禁止,我什至不清楚。在您的 htaccess 中,您使用blog... 重写链接,robots.txt 不是这种情况,也不是问题所在。你写了谷歌说robots.txt...用谷歌网站管理员工具再次测试你的robots.txt。还有你的sitemap.xml...
  • 我更改了机器人(> 24 小时前),我得到了同样的错误,虽然我可以“以谷歌的身份获取”我的站点地图中的 URL,并且在我“将 [URL] 发送到索引”。我仍然收到 URL 不可抓取的警告。有什么帮助吗?
  • 您的 html 代码中没有任何内容? ex: &lt;meta name="robots"
猜你喜欢
  • 2015-06-08
  • 1970-01-01
  • 2018-06-20
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 2013-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多