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