【问题标题】:Why isn't prerender.io service reached with this configuration?为什么使用此配置无法访问 prerender.io 服务?
【发布时间】:2016-05-14 21:28:56
【问题描述】:

我拥有一个 Angular 应用程序和一个 Apache 服务器。

我在<head> 部分和$locationProvider.html5Mode(true); 上设置了<meta name="fragment" content="!" />

在我的 Apache 服务器上的 .htaccess 文件中,我添加了这部分:

<IfModule mod_headers.c>
    RequestHeader set X-Prerender-Token "My_Token"
</IfModule>

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on

            # Don't rewrite files or directories
            RewriteCond %{REQUEST_FILENAME} -f [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^ - [L]

            <IfModule mod_proxy_http.c>
                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://example.com/$2 [P,L]
           </IfModule>
            # Rewrite everything else to index.html to allow html5 state links
            RewriteRule ^ index.html [L]
</IfModule>

但是,当我运行以下命令时:
curl http://example.com?_escaped_fragment_=
我没有得到预渲染的文件。

听起来Prerender的服务根本没有触发。

我错过了一些配置吗?

【问题讨论】:

    标签: html angularjs apache .htaccess prerender


    【解决方案1】:

    您可能会从这里为您的索引提供服务:

            RewriteCond %{REQUEST_FILENAME} -f [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^ - [L]
    

    您可以尝试将预渲染配置移到高于该部分的位置吗?

    【讨论】:

    • 肯定是关于 htaccess 中权限集的问题。我检查。导致 403 错误的是序列 [P,L] 中的 P 标志。这是一个已知问题吗?
    • 我刚刚问过的相关问题:stackoverflow.com/questions/35224988/…
    猜你喜欢
    • 2017-02-19
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2019-10-22
    相关资源
    最近更新 更多