关于设置的信息:
我已经在我自己的服务器 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]
问题:
使用预渲染时,元数据未加载到 Skype、Reddit、Twitter。将 url 重写为旧的 PHP 网站:http : //art.example.net(目前在 htaccess 中评论)确实有效。因为 PHP 和 Angular 网站上的所有元标记都是相同的,所以预渲染器很可能是问题的原因。
来自 Twitter 的错误示例(https://cards-dev.twitter.com/validator using 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 中工作(带有修改的用户代理标头)。我只是不知道为什么它对其他一些代理不起作用。
您的重写规则应该是代理,而不是重定向。重定向到您的预渲染服务器会导致各种问题,包括告诉 Google 将用户从搜索结果直接发送到您的预渲染服务器(这真的很糟糕!)。
重写规则部分应该是:
RewriteRule ^(.*)$ http://example.nl:3000/http://www.example.nl/$1? [P,L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句