有关设置的信息:

我已经在自己的服务器Ubuntu 16上成功安装了prerender(https://github.com/prerender/prerender)。

这是我的.htaccess文件,它在检测到搜寻器时将URL重写为预渲染。示例:http://www.example.nl/63/Merry变为http://example.nl:3000/http://www.example.nl/63/Merry

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|redditbot|slackbot|msnbot|googlebot|duckduckbot|bingbot|rogerbot|linkedinbot|embedly|flipboard|tumblr|bitlybot|SkypeUriPreview|nuzzel|Discordbot|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$  http://example.nl:3000/http://www.example.nl/$1? [R=301,L]
#RewriteRule ^(.*)$  http://art.example.net/$1? [R=301,L]

RewriteRule ^(.*)/(.*)$ /#$1/$2 [NC,L]


问题:

使用prerender时,不会在Skype,Reddit,Twitter上加载元数据。将该URL重写到旧的PHP网站:http://art.example.net(当前在htaccess中已注释)确实有效。由于PHP和Angular网站上的所有meta标签都相同,因此prerenderer很可能是问题的原因。

来自使用Prerender的Twitter(https://cards-dev.twitter.com/validator使用url:http://example.nl/63/Merry)的错误示例:

ERROR: Failed to fetch page due to: HttpConnectionTimeout
WARN:  this card is redirected to http://example.nl:3000/http://www.example.nl/63/Merry


重定向到art.example.net时的Twitter(也使用主URL:http://example.nl/63/Merry

INFO:  Page fetched successfully
INFO:  19 metatags were found
INFO:  twitter:card = summary_large_image tag found
INFO:  Card loaded successfully
WARN:  this card is redirected to http://art.example.net/63/Merry


使用PHP版本有效,并且所有元数据都已加载。

将来,我想完全删除PHP网站,因此,我非常希望它可以与Prerender一起使用。
Prerender确实适用于Discord和Postman(具有修改的User Agent标头)。我只是不知道为什么它不适用于某些其他代理。

最佳答案

您的重写规则应该是代理,而不是重定向。重定向到您的预渲染服务器会引起各种问题,包括告诉Google将用户从搜索结果直接发送到您的预渲染服务器(这确实很糟糕!)。

重写规则部分应为:

RewriteRule ^(.*)$  http://example.nl:3000/http://www.example.nl/$1? [P,L]

关于javascript - Prerender + AngularJS-爬行器超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43954012/

10-09 22:55