.htaccess - 重写 AJAX 抓取规则

标签 .htaccess mod-rewrite seo

要重定向 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]

第一次成功从上面的 Google 抓取的 URL 重定向到以下 URL:

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

请帮我写什么规则。

最佳答案

你可以试试这个规则:

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

关于.htaccess - 重写 AJAX 抓取规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22060774/

相关文章:

php - 使用 .htaccess 和友好 url 的网站翻译

apache - 如何在 .htaccess 中为特定 IP 地址设置 cookie

.htaccess - 仅允许通过 .htaccess 直接访问特定文件夹名称

php - 在 .htaccess 中使 php_value 成为条件?

.htaccess - 如何在 WampServer 中配置 CakePHP 的 .htaccess 文件?

.htaccess - Prestashop SEO 的网址重复

wordpress - 谷歌搜索结果问题

.htaccess - 我应该从哪里了解 htaccess

apache - .htaccess 被解析和 RewriteRule 指令运行多少次?

php - noscript 谷歌快照,安全的方式