Skip to content

Instantly share code, notes, and snippets.

@thoop
Last active December 27, 2019 05:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoop/6be274259bdeee4e2363e008577bff2a to your computer and use it in GitHub Desktop.
Save thoop/6be274259bdeee4e2363e008577bff2a to your computer and use it in GitHub Desktop.
Prerender.io IIS web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!--# Only proxy the request to Prerender if it's a request for HTML-->
<rule name="Prerender" stopProcessing="true">
<serverVariables>
<set name="HTTP_X_PRERENDER_TOKEN" value="[...your token...]" />
</serverVariables>
<match url="^(?!.*?(\.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))(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator" />
<add input="{QUERY_STRING}" pattern="_escaped_fragment_" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="https://service.prerender.io/https://yourwebsite.com/{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
@thoop
Copy link
Author

thoop commented Oct 18, 2018

You also need to add HTTP_X_PRERENDER_TOKEN to the Allowed Server Variables in IIS for the prerender token to be sent correctly to our prerender.io service.

@jaycincotta
Copy link

There are also two other very important details we learned for using prerender.io with IIS:

  1. Install the ARR
  2. Check the ARR Enable Proxy flag otherwise, Rewrite to any external site will return 404

@jprakashpillai
Copy link

hi
i had update my angular 8 website web.config file with the above rules but still my site pagesource not showing seo details
please help me regarding this.
my link is
http://oncloudinfotech.info/

Modified web.config

  <rule name="Angular Routes" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll">
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="/index.html" />
  </rule>
            <rule name="Prerender" stopProcessing="true">
                <serverVariables>
                    <set name="HTTP_X_PRERENDER_TOKEN" value="xxxxx" />
                </serverVariables>
                <match url="^(?!.*?(\.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))(.*)" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_USER_AGENT}" pattern="googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator" />
                    <add input="{QUERY_STRING}" pattern="_escaped_fragment_" ignoreCase="false" />
                </conditions>
                <action type="Rewrite" url="https://service.prerender.io/http://oncloudinfotech.info/{R:2}" />
            </rule>
</rules>
</system.webServer>

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