在 one.com 服务器上使用 Prerender.io 与 AngularJS
Use Prerender.io on one.com server with AngularJS
对于我的 AngularJS 应用程序,我尝试通过 one.com 在服务器上使用 Prerender.io 的服务。使用的网络服务器是 Apache
.
我已经尝试使用以下 .htaccess
文件(比较 https://gist.github.com/thoop/8072354)
# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change http://example.com (at the end of the last RewriteRule) to your website url
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "YOUR_TOKEN"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# If requested resource exists as a file or directory
# (REQUEST_FILENAME is only relative in virtualhost context, so not usable)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
# Go to it as is
RewriteRule ^ - [L]
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
# Only proxy the request to Prerender if it's a request for HTML
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://service.prerender.io/http://%{HTTP_HOST}/ [P,L]
# If non existent
# Accept everything on index.html
RewriteRule ^ /index.html [L]
</IfModule>
我尝试使用 Google 网站站长工具 (Fetch as Google
) 来检查它是否有效。不幸的是,Google 机器人正在获取的网站不是 Prerender.io.
预获取的网站
可能是RewriteRule
中的P
标志没有被执行。但我不太确定。
Fetch as Google 有一个已知问题,它不检查转义片段协议。实际的 Googlebot 没有这个问题,它会检查元片段标签并添加转义片段参数。
#! URLs 或 HTML5 推送状态 URLs 你还需要手动附加 ?_escaped_fragment_=。
这是 Google 对此的回答:https://productforums.google.com/forum/#!topic/webmasters/YaOZrKGYrGA
如果你有#! URL 喜欢
http://www.example.com/#!/user/1
那么您将需要 Fetch as Google fetch this URL
http://www.example.com/?_escaped_fragment_=/user/1
如果你有一个非 #! URL 喜欢
http://www.example.com/user/1
那么您将需要 Fetch as Google fetch this URL
http://www.example.com/user/1?_escaped_fragment_=
如果您仍然遇到问题,请随时通过 todd@prerender.io 给我发电子邮件!
对于我的 AngularJS 应用程序,我尝试通过 one.com 在服务器上使用 Prerender.io 的服务。使用的网络服务器是 Apache
.
我已经尝试使用以下 .htaccess
文件(比较 https://gist.github.com/thoop/8072354)
# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change http://example.com (at the end of the last RewriteRule) to your website url
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "YOUR_TOKEN"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# If requested resource exists as a file or directory
# (REQUEST_FILENAME is only relative in virtualhost context, so not usable)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
# Go to it as is
RewriteRule ^ - [L]
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
# Only proxy the request to Prerender if it's a request for HTML
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://service.prerender.io/http://%{HTTP_HOST}/ [P,L]
# If non existent
# Accept everything on index.html
RewriteRule ^ /index.html [L]
</IfModule>
我尝试使用 Google 网站站长工具 (Fetch as Google
) 来检查它是否有效。不幸的是,Google 机器人正在获取的网站不是 Prerender.io.
可能是RewriteRule
中的P
标志没有被执行。但我不太确定。
Fetch as Google 有一个已知问题,它不检查转义片段协议。实际的 Googlebot 没有这个问题,它会检查元片段标签并添加转义片段参数。
#! URLs 或 HTML5 推送状态 URLs 你还需要手动附加 ?_escaped_fragment_=。
这是 Google 对此的回答:https://productforums.google.com/forum/#!topic/webmasters/YaOZrKGYrGA
如果你有#! URL 喜欢
http://www.example.com/#!/user/1
那么您将需要 Fetch as Google fetch this URL
http://www.example.com/?_escaped_fragment_=/user/1
如果你有一个非 #! URL 喜欢
http://www.example.com/user/1
那么您将需要 Fetch as Google fetch this URL
http://www.example.com/user/1?_escaped_fragment_=
如果您仍然遇到问题,请随时通过 todd@prerender.io 给我发电子邮件!