Integrate with IIS
Integrating Prerender.io with IIS doesn't need a middleware to be installed, you just need to add some well constructed URL rewrite rules to your server configuration.
Prerequisites:
- The URL rewrite and the ARR modules need to be installed and enabled
https://www.iis.net/downloads/microsoft/url-rewrite
https://www.iis.net/downloads/microsoft/application-request-routing - Check the “Enable proxy” checkbox located in Application Request Routing feature view in IIS Manager.
Add the rules
- Navigate to IIS manager > Select your server > Sites > Select your site > Open URL Rewrite.
- Click "Add rule(s)..." on the right hand side and select "Blank rule".
- Name the rule (e.g. Prerender.io rewrite rule)
- Set up the "Match URL" section to look like this:
- Requested URL: Does Not Match the Pattern
- Using: Regular Expression
- Pattern: (\.js|\.json|\.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|\.svg)
- Check ignore case if your site URLs are case insensitive
- Add two rules in the "Conditions" section:
- Rule 1:
- Condition input: {HTTP_USER_AGENT}
- Check if input string: Matches the Pattern
- Pattern: googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp
- Check "Ignore case"
- Rule 2:
- Condition input: {QUERY_STRING}
- Check if input string: Matches the Pattern
- Pattern: _escaped_fragment_
- Set the "Logical grouping" to "Match Any".
- Rule 1:
- In the "Server Variables" section add your Prerender.io token to be forwarded to us:
- Click Add...
- Server variable name: HTTP_X_PRERENDER_TOKEN
- Value: [YOUR TOKEN]
- Check "Replace the existing value"
- Set up the "Action" section to match the following:
- Action type: Rewrite
- Rewrite URL: https://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}
- Check "Append query string"
- To get better logging, check "Log rewritten URL" (optional)
- Check "Stop processing of subsequent rules" (optional, this may also depend on your setup)
Notes:
- Change the "Rewrite URL" to use https if your site enforces https.
- This setup guide is just a template, your application may have special needs that need to be reflected in these rules.
- this guide assumes that your IIS server is publicly accessible from the Internet. If you want to set this up for a local development environment, you need to run the open source Prerender component (https://github.com/prerender/prerender) locally on your computer, then use the URL of that service (e.g. http://localhost:3000) in point 7/b, replacing the https://service.prerender.io URL.