Create a gist now

Instantly share code, notes, and snippets.

@Stanback /.htaccess
Last active Sep 29, 2016

Example Apache configuration for serving pre-rendered HTML from Javascript pages/apps using the Prerender Service at
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /prerender-test/
# Virtual/pushState URIs (requests not matching an existing file get forwarded to index.html)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.html [L]
<IfModule mod_proxy_http.c>
# Enable prerendering for .html and directory index files
RewriteCond %{HTTP_USER_AGENT} googlebot|yahoo|bingbot|baiduspider [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_|prerender=1
RewriteCond %{HTTP_USER_AGENT} !^Prerender
RewriteRule ^(.*\.html)?$$1 [P,L]
# Optionally add a ProxyPassReverse directive to ensure that 301/302 redirects
# issued by the prerender service are correctly forwarded to the client.
# Note that this must be located in your Apache config rather than .htaccess
# <IfModule mod_proxy_http.c>
# ProxyPassReverse /prerender-test/
# </IfModule>

Here is a more extensive list of some of the latest bot user agents sourced from



Thanks for the list @homerjam!


Hey guys, this isn't working for me. The request hits prerender but everything gets loaded into prerender as index.html and returns a blank html page: <html><head></head><body></body></html> (I am using User-Agent Switcher as a chrome extension to test behavior).

Before I switched to the pushState method, prerender was working with the "#!" method and I didn't need the following:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.html [L]



Hey again. Just wanted to let you guys know that I got things figured out but the fallback URL condition I listed above needed to be below the prerender proxy rewrite rule or else the page falls back to index.html before there is a chance to send the url to prerender.


Googlebot is starting to render Javascript so you may want to remove it from the user agents list (after testing in webmaster tools)



How to blacklist a single url path or multiple url paths. Compares using regex, so be specific when possible. If a blacklist is supplied, all url's will be prerendered except ones containing a blacklist path.

Do you have any solution with htaccess . This exist for other plugins


Hi @yagobski !, did you find a solution for blacklisting paths using htaccess?, i have the same problem :/


Hi everyone. I'm getting kind of crazy with this...
My prerender server is on its own subdomain,
My main domain,, is where I have Angular running.
Prerender server is running fine. returns rendered html.

So in my Apache middleware, on, I have the conditions and the rules to proxy the request.

## Enable SSL ProxyEngine  ##  cannotbe on .htaccess
SSLProxyEngine on

## Conditions
## cannot have useragent prerender, and.... ##
RewriteCond %{HTTP_USER_AGENT} !^prerender [NC]  

## has one of these useragents, or..... ##
RewriteCond %{HTTP_USER_AGENT} facebookexternalhit|facebot|yandexbot|google|bingbot|duckduckbot|baiduspider|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkshare|w3c_validator|exabot|ia_archiver|msnbot|slurp|wget|curl|postrank|applebot|semrushbot|addthis [NC,OR]   

## has "_escaped_fragment_" or "prerender=1" as queries  ##
RewriteCond %{QUERY_STRING} _escaped_fragment_|prerender=1 [NC]   

## Then if request is .html, send a proxy request to of url)  ##
RewriteRule ^(.*.html)?$$1 [P,L]

It should work. But requests like only return the index page.
And on the logs of the prerender server I have: GET /
This is clearly wrong but I don't understand why.

Any sugestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment