重定向 .htaccess 中的机器人和爬虫 对于 AngularJS 页面


Redirect bots and crawlers in .htaccess for AngularJS pages

我正在使用AngularJS作为Web应用程序,并创建了一个PHP脚本,该脚本使用Angular路由创建的URL参数动态生成元丰富的页面,专门用于社交共享目的(未SEO索引)。我需要将搜索和社交抓取机器人重定向到 SEO 友好的生成页面。

我目前正在尝试仅将 http://www.example.com/v4/songs/prince/purple-rain 重定向到抓取工具/机器人的 http://www.example.com/static/static.php/songs/prince/purple-rain

我正在使用以下 .htaccess 代码

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/1.0|facebookexternalhit/1.1|Facebot|Twitterbot|Pinterest|Google.*snippet) [NC]
RewriteRule ^(.*)$ http://www.example.com/static/static.php/$1 [R=301,NC]
</ifModule>
RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) index.html [NC,L]

我目前收到所有棉绒的抓取错误,说"无效的URL"或"无数据"。它作为普通的 301 重定向工作正常,但显然我不希望这样。我的 .htaccess 文件有什么问题?

您是否尝试过使用第二个条件,例如

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$

尽管您(角度路由

和位置提供程序)更改了 URL,但在执行角度路由之前(爬网程序不会发生这种情况),它们具有 #!,使爬网程序仅将路径的其余部分视为参数。使用_escaped_fragment_您可以以某种方式区分爬网程序,然后将它们重定向到已评估社交变量的快照。见 yearofmoo angular 和 seo