如何检查prerender.io是否在我的angularjs网站上正常工作?

时间:2014-08-21 01:32:19

标签: javascript angularjs .htaccess seo prerender

我遵循了这个教程: http://www.ng-newsletter.com/posts/serious-angular-seo.html

我从这里使用修改过的apache conf(原来没用,我改了HTTP_USER_AGENT位) https://gist.github.com/thoop/8072354

现在我的.htaccess文件看起来像这样

    # 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 "MY TOKEN"
    </IfModule>

    <IfModule mod_rewrite.c>
        RewriteEngine on

        Options +FollowSymLinks
        #RewriteRule ^api/(.*)$ http://vivule.ee/api/$1 [P,L]

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

        # Rewrite everything else to index.html to allow html5 state links
        RewriteRule ^ index.html [L]

        RewriteCond %{REQUEST_URI}  ^/$
        RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
        RewriteRule ^(.*)$ /snapshots/%1? [NC,L]

        # Prerender.io stuff
        <IfModule mod_proxy_http.c>
            RewriteCond %{HTTP_USER_AGENT} Googlebot|bingbot|Googlebot-Mobile|Baiduspider|Yahoo|YahooSeeker|DoCoMo|Twitterbot|TweetmemeBot|Twikle|Netseer|Daumoa|SeznamBot|Ezooms|MSNBot|Exabot|MJ12bot|sogou\sspider|YandexBot|bitlybot|ia_archiver|proximic|spbot|ChangeDetection|NaverBot|MetaJobBot|magpie-crawler|Genieo\sWeb\sfilter|Qualidator.com\sBot|Woko|Vagabondo|360Spider|ExB\sLanguage\sCrawler|AddThis.com|aiHitBot|Spinn3r|BingPreview|GrapeshotCrawler|CareerBot|ZumBot|ShopWiki|bixocrawler|uMBot|sistrix|linkdexbot|AhrefsBot|archive.org_bot|SeoCheckBot|TurnitinBot|VoilaBot|SearchmetricsBot|Butterfly|Yahoo!|Plukkie|yacybot|trendictionbot|UASlinkChecker|Blekkobot|Wotbox|YioopBot|meanpathbot|TinEye|LuminateBot|FyberSpider|Infohelfer|linkdex.com|Curious\sGeorge|Fetch-Guess|ichiro|MojeekBot|SBSearch|WebThumbnail|socialbm_bot|SemrushBot|Vedma|alexa\ssite\saudit|SEOkicks-Robot|Browsershots|BLEXBot|woriobot|AMZNKAssocBot|Speedy|oBot|HostTracker|OpenWebSpider|WBSearchBot|FacebookExternalHit [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))(.*) http://service.prerender.io/http://vivule.ee/$2 [P,L]
        </IfModule>

    </IfModule>

但是,如果我使用prerender.io推荐的转义片段进行测试,似乎什么都没发生。您可以自行检查:http://vivule.ee/?_escaped_fragment_=http://vivule.ee/0/?_escaped_fragment_=

如果我尝试了facebook共享功能,它仍然会获得未被角度脚本修改的html。 (尝试使用此工具:https://developers.facebook.com/tools/debug/og/object/以获取最新数据,但无济于事。)

如何测试预呈现是否正常工作?

1 个答案:

答案 0 :(得分:8)

好的,我修好了,好像我所要做的就是移动&#34; RewriteRule ^ index.html [L]&#34;到.htaccess文件的末尾。 .htaccess文件是从上到下读取的,我猜它之前从未进入过预渲染部分。

这里的.htaccess代码有效:             #如果要缓存网址并查看抓取统计信息,请将YOUR_TOKEN更改为预呈现令牌并取消注释该行             #将http://example.com(在最后一次RewriteRule的末尾)更改为您的网站网址

        <IfModule mod_headers.c>
            RequestHeader set X-Prerender-Token "MY SECRET TOKEN"
        </IfModule>

        <IfModule mod_rewrite.c>
            RewriteEngine on

            Options +FollowSymLinks
            #RewriteRule ^api/(.*)$ http://vivule.ee/api/$1 [P,L]

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


            RewriteCond %{REQUEST_URI}  ^/$
            RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
            RewriteRule ^(.*)$ /snapshots/%1? [NC,L]

            # Prerender.io stuff
            <IfModule mod_proxy_http.c>
                RewriteCond %{HTTP_USER_AGENT} Googlebot|bingbot|Googlebot-Mobile|Baiduspider|Yahoo|YahooSeeker|DoCoMo|Twitterbot|TweetmemeBot|Twikle|Netseer|Daumoa|SeznamBot|Ezooms|MSNBot|Exabot|MJ12bot|sogou\sspider|YandexBot|bitlybot|ia_archiver|proximic|spbot|ChangeDetection|NaverBot|MetaJobBot|magpie-crawler|Genieo\sWeb\sfilter|Qualidator.com\sBot|Woko|Vagabondo|360Spider|ExB\sLanguage\sCrawler|AddThis.com|aiHitBot|Spinn3r|BingPreview|GrapeshotCrawler|CareerBot|ZumBot|ShopWiki|bixocrawler|uMBot|sistrix|linkdexbot|AhrefsBot|archive.org_bot|SeoCheckBot|TurnitinBot|VoilaBot|SearchmetricsBot|Butterfly|Yahoo!|Plukkie|yacybot|trendictionbot|UASlinkChecker|Blekkobot|Wotbox|YioopBot|meanpathbot|TinEye|LuminateBot|FyberSpider|Infohelfer|linkdex.com|Curious\sGeorge|Fetch-Guess|ichiro|MojeekBot|SBSearch|WebThumbnail|socialbm_bot|SemrushBot|Vedma|alexa\ssite\saudit|SEOkicks-Robot|Browsershots|BLEXBot|woriobot|AMZNKAssocBot|Speedy|oBot|HostTracker|OpenWebSpider|WBSearchBot|FacebookExternalHit [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))(.*) http://service.prerender.io/http://vivule.ee/$2 [P,L]
            </IfModule>

            # Rewrite everything else to index.html to allow html5 state links
            RewriteRule ^ index.html [L]

        </IfModule>