ajax爬取的Apache重写条件

标签 apache mod-rewrite angularjs seo

我正在尝试实现 google ajax crawlable snapshots .

为此,我在 .htaccess 中添加了以下重写条件,如下所示

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ /snapshots/%1.html? [NC,L]

它工作正常,但在以下情况下失败。

www.mysite.com/#!/

这是在谷歌文档中作为 www.mysite.com/?_escaped_fragment_=/ 抓取的。

我的快照目录中有一个准备好的 index.html 来处理此类请求

但是对于上面的重写条件,它正在搜索 .html 并且结果是 403 响应。如果您能帮我修复以针对此类请求提供 index.html 页面

,我将不胜感激

最佳答案

您将需要针对上述用例的附加规则。将此规则插入现有规则之上:

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/$ [NC]
RewriteRule ^ /snapshots/index.html? [NC,L]

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.+)$ [NC]
RewriteRule ^ /snapshots/%1.html? [NC,L]

关于ajax爬取的Apache重写条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18180626/

相关文章:

hashbang 编码后的 AngularJS 斜线

php - UTF-8贯穿始终

在 Mac OS X 上使用第二个实例的 Apache 命令

apache - Html 页面的 URL 重写

regex - RewriteRule 无法编译正则表达式

angularjs - 使用来自浏览器的信息对多个页面进行 E2E 测试

javascript - textarea 上的 Angular $sce.trustAsHtml 与 ng-model 相同

java - 使用 apache commons exec 运行简单的 cmd.exe 命令

php - 来自用户而不是 Nginx 反向代理服务器的 REMOTE_ADDR IP

apache - Htaccess mod 重写不起作用