【发布时间】:2017-05-13 13:59:28
【问题描述】:
设置信息:
我已经在自己的服务器 Ubuntu 16 上成功安装了预渲染 (https://github.com/prerender/prerender)。
这是我的 .htaccess,它会在检测到爬虫时将 url 重写为 prerender。示例: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]
问题:
使用预渲染时,元数据未在 Skype、Reddit、Twitter 上加载。重写旧 PHP 网站的 url:http://art.example.net(目前在 htaccess 中注释)确实有效。因为 PHP 和 Angular 网站上的所有元标记都是相同的,所以 prerenderer 很可能是问题的原因。
来自 Twitter 的错误示例(https://cards-dev.twitter.com/validator 使用 url:http://example.nl/63/Merry)使用 Prerender:
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 标头)。我只是不知道为什么它不适用于其他一些代理。
【问题讨论】:
标签: javascript angularjs prerender