【问题标题】:Re-write rules for AJAX Crawling重写 AJAX 爬取规则
【发布时间】:2014-03-30 10:12:35
【问题描述】:

要重定向mysite.com/category1 URL,以下规则可以正常工作:

RewriteRule ^category1([^?]*) index.php?route=category&path=1 [L,NC]

对于 AJAX 抓取,我需要使用 #!哈希片段。因此,新 URL 将变为 mysite.com/category1#!。然而, #!由 Google 自动转换为 _escaped_fragment_。

因此,为了抓取,Google 使用以下 URL 获取我的服务器:

mysite.com/index.php?_escaped_fragment_=category1 

以下规则:

RewriteCond %{QUERY_STRING} ^escaped_fragment_=(category1)$ 
RewriteRule ^$ index.php?route=category&path=1&%1 [R=301,NC,QSA,L]

第一次成功从上述谷歌抓取的网址重定向到以下网址:

mysite.com/index.php?route=category&path=1&_escaped_fragment_=category1 

再一次,不需要的循环重定向到:

mysite.com/category1 

简单地说,我需要重写规则来重定向:

mysite.com/index.php?_escaped_fragment_=category1

到:

mysite.com/index.php?route=category&path=1&_escaped_fragment_=category1

请帮我写什么规则。

【问题讨论】:

  • 不幸的是,# 之后的 URL 片段不会被 Web 服务器看到。所以当你的 AJAX url 是 mysite.com/category1#! 时,Apache 只会得到 mysite.com/category1 所以你不能匹配它。最好在您的 Javascript 本身中执行此操作。
  • 我不想查看 mysite.com/category1#!在浏览器上。我的站点地图将此 URL 提交给 Google。然后,Google 将其转换为 mysite.com/category1_escaped_fragment_ 和他们的机器人使用这个修改后的 URL 访问我的 Apache 服务器。因此,Web 服务器不需要处理 #!,而是需要处理 escaped_fragment
  • 哦,好的,所以服务器得到:/index.php?route=category&path=1&_escaped_fragment_ URI?如果是,那么应该将其重写到哪里?
  • 请注意,如果我获取 mysite.com/index.php?route=category&path=1#!通过 Google 网站管理员工具,我的网络服务器成功获取了该请求的 mysite.com/index.php?route=category&path=1&_escaped_fragment_。但是,我需要获取其永久 URL mysite.com/category1#!由 Google 网站管理员工具提供。

标签: .htaccess mod-rewrite seo


【解决方案1】:

你可以试试这个规则:

RewriteRule ^category([0-9]+)/?$ index.php?route=category&path=$1 [L,NC,QSA]

【讨论】:

  • 对不起,我最后一个问题背后的问题是错误的。实际上,它需要从 "mysite.com/category1?_escaped_fragment_=" 转换为 "to mysite.com/index.php?route=category&path=1&_escaped_fragment_" URL。我该怎么做?
  • 不,这条规则对我不起作用。我尝试过不同的方法。以下规则最初重定向到预期的 url,RewriteCond %{QUERY_STRING} ^(escaped_fragment_=)(category1)$ RewriteRule ^$ index.php?route=category&path=1&%1 [R=301,NC,QSA,L ] 但是,它会重定向到永久 url:“mysite.com/category1”,依此类推,它会生成 AJAX 页面。如果它带有_escaped_fragment,它不应该重定向到AJAX页面。
  • 这真的很混乱,不清楚你真正想要什么。您能否编辑您的问题并清楚地解释您的源 URL 和您预期的重写。
  • 感谢您为解决我的问题而进行的长时间讨论,尽管我处理了这个问题不明智。根据你的建议,我编辑了这个问题。令人惊讶的是,编辑后的问题以某种方式说明了我对原始问题的可能答案。我对重定向感到困惑。此永久重定向代码是在另一个 php 文件中编写的。
猜你喜欢
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多