How to check if prerender.io is working correctly on my angularjs site?

yodalr picture yodalr · Aug 21, 2014 · Viewed 7.9k times · Source

I followed this tutorial: http://www.ng-newsletter.com/posts/serious-angular-seo.html

And I'm using modified apache conf from here (original didn't work, I changed the HTTP_USER_AGENT bit) https://gist.github.com/thoop/8072354

Right now my .htaccess file looks like this

    # 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>

But if I test with escaped fragment like it's recommended on prerender.io, nothing seems to happen. You can check yourself: http://vivule.ee/?_escaped_fragment_= or http://vivule.ee/0/?_escaped_fragment_=

And if I try out the facebook sharing function, it still get's the html which is not modified by the angular script. (Tried this tool: https://developers.facebook.com/tools/debug/og/object/ to get the latest data, but to no avail).

Any ideas how to test if the prerender is even working?

Answer

yodalr picture yodalr · Aug 23, 2014

Ok, I fixed it, seems like all I had to do is move the "RewriteRule ^ index.html [L]" to the end of the .htaccess file. .htaccess file is read from top to bottom, and I guess it never go to the prerender part before.

Here's the .htaccess code that works: # 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 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>