【问题标题】:Use Prerender.io on one.com server with AngularJS使用 AngularJS 在 one.com 服务器上使用 Prerender.io
【发布时间】:2015-06-19 12:01:33
【问题描述】:

对于我的 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}/$2 [P,L]

    # If non existent
    # Accept everything on index.html
    RewriteRule ^ /index.html [L]
</IfModule>

我尝试使用 Google 网站管理员工具 (Fetch as Google) 检查它是否有效。不幸的是,Google bot 正在获取的网站不是 Prerender.io 预获取的网站。

可能是RewriteRule 中的P 标志未执行。但我不太确定。

【问题讨论】:

    标签: angularjs apache .htaccess prerender


    【解决方案1】:

    Fetch as Google 存在一个已知问题,即它不检查转义片段协议。实际的 Googlebot 没有这个问题,它会检查元片段标记并添加转义片段参数。

    对于任何一个 #!您仍需要手动附加 ?_escaped_fragment_= 的 URL 或 HTML5 推送状态 URL。

    这是来自 Google 的答案:https://productforums.google.com/forum/#!topic/webmasters/YaOZrKGYrGA

    如果你有 #!网址如 http://www.example.com/#!/user/1 那么你会想要让谷歌抓取这个网址 http://www.example.com/?_escaped_fragment_=/user/1

    如果你有一个非 #!网址如 http://www.example.com/user/1 那么你会想要让谷歌抓取这个网址 http://www.example.com/user/1?_escaped_fragment_=

    如果您仍然遇到问题,请随时通过 todd@prerender.io 给我发送电子邮件!

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 2017-09-13
      • 2014-09-25
      相关资源
      最近更新 更多