【发布时间】: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