Skip to content

Instantly share code, notes, and snippets.

@blowsie
Last active September 6, 2021 22:26
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blowsie/04c183c62a432f6450c9 to your computer and use it in GitHub Desktop.
Save blowsie/04c183c62a432f6450c9 to your computer and use it in GitHub Desktop.
Prerender IIS Web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Prerender-Token" value="XXXXXXXXXXXXX" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<!--# Only proxy the request to Prerender if it's a request for HTML-->
<rule name="Prerender" stopProcessing="true">
<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="baiduspider|facebookexternalhit|twitterbot" />
<add input="{QUERY_STRING}" pattern="_escaped_fragment_" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="http://service.prerender.io/http://yourwebsite.com/{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
@sivastyle
Copy link

Did you got this working ?

@MMRandy
Copy link

MMRandy commented Apr 10, 2015

This worked for us. Our rewrite is as follows:

        <rule name="Seo rewrite rule" stopProcessing="true">
          <serverVariables>
            <set name="HTTP_X_PRERENDER_TOKEN" value="[...your token...]" />
          </serverVariables>
          <conditions>
            <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
          </conditions>
          <action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
        </rule>

As far as the "allowableServerVariables", we handled this through the IIS and clicking either the Default Web Site of the Site itself, then clicking the URL Rewrite module icon, then select View Server Variables, and add the HTTP_X_PRERENDER_TOKEN variable name to the list.

With this in place, we were now able to append the escaped_fragment querystring to our urls and see the rewritten results after coming back through the server. You should also be able to verify in your Account page on PreRender.io that the pages are being cached.

HTH,
Randy

@blackjack-8
Copy link

@MMRandy thanks. It works after added the variable name on the iis list.

@krusk
Copy link

krusk commented May 2, 2015

I am using Azure and Remote administrating IIS, but I don't see the "View Server Variables" option. Where is that?

@e06widu
Copy link

e06widu commented Jul 20, 2015

I am using above rule but it gives me 404 error when I try to load http://yourwebsite.com/?_escaped_fragment_=

But after I change the type of action to Redirect it redirect fine.
Does some one have an idea?

@Yushell
Copy link

Yushell commented Aug 24, 2015

I am also gettin a 404 error. @e06widu did you make it work? Or does someone know why the 404 error is being generated?

Error:

HTTP Error 404.4 - Not Found
The resource you are looking for does not have a handler associated with it.

Most likely causes:
The file extension for the requested URL does not have a handler configured to process the request on the Web server.

Detailed Error Information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x8007007b
Requested URL http://localhost:80/home/1?_escaped_fragment_=
Physical Path C:\inetpub\wwwroot\PrerenderSample\home\1
Logon Method Anonymous
Logon User Anonymous

@Swimburger
Copy link

I tried the first config and it doesn't do it,
@MMRandy 's config seemed to do something but I get a 500 URL Rewrite Module Error.
I'm on Azure using Azure websites. Anyone got an idea what's going wrong?
Also, I'm using html5 mode.

@Swimburger
Copy link

After debugging for a long time, I got it (kinda) working on Azure Websites.

<?xml version="1.0"?>
<configuration>
        <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="X-Prerender-Token" value="mytoken" />
            </customHeaders>
        </httpProtocol>
        <rewrite>
            <rules>
                <!--# Only proxy the request to Prerender if it's a request for HTML-->
                <rule name="Prerender" stopProcessing="true">
                    <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="baiduspider|facebookexternalhit|twitterbot|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="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
                </rule>
                <rule name="Redirect To Index" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

By default, you can't do a proxy request, that's why I needed to enable proxy in the Azure Website.
I created an applicationHost.xdt file with the following content, here is more info.

<?xml version="1.0"?>  
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
    <system.webServer>  
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="true"  
        reverseRewriteHostInResponseHeaders="false" />  
    </system.webServer>  
</configuration> 

I still see "You need to install your Prerender token before you can start viewing recache stats. Click here to install the token on your platform." on the prerender site, but I do get the desired results.
I guess it's something with the headers.
I couldn't get setting the header working like @MMRandy in Azure, even though I did add the header to the same xdt file to allow it.
I've posed a question on the Azure MSDN forum about it.

@Swimburger
Copy link

@krusk , I got it working on Azure.
You have to upload this file one level lower than my site root.
You add files outside your site at yourwebsite.scm.azurewebsites.net > Debug Console > CMD .
This file (applicationHost.xdt) will enable ARR and insert the prerender header to the allowed variables.

<?xml version="1.0"?>  
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
    <system.webServer>  
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false"  
        reverseRewriteHostInResponseHeaders="false" />
        <rewrite>
            <allowedServerVariables>
                <add name="X-Prerender-Token" xdt:Transform="InsertIfMissing" />
            </allowedServerVariables>
        </rewrite>  
    </system.webServer>  
</configuration>

My web.config looks like this.
The second rule is for html5 mode.

<?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="X-Prerender-Token" value="YOURTOKEN" />
                    </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="baiduspider|facebookexternalhit|twitterbot" />
                        <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
                </rule>
                <rule name="Redirect To Index" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Now it's important to restart your website! When the first request comes in, the xdt will execute the transformations.

You can follow your logstream to see if they are added at https://yourwebsite.scm.azurewebsites.net/api/logstream
It looks like this:

2015-09-28T21:49:28  Welcome, you are now connected to log-streaming service.
2015-09-28T21:49:34 sandboxproc.exe C:\DWASFiles\Sites\yoursite\Temp\applicationhost.config
2015-09-28T21:49:34 env XPROC_TYPENAME=Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper, Microsoft.Web.Hosting, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
2015-09-28T21:49:34 env XPROC_METHODNAME=Transform
2015-09-28T21:49:34 Start 'site' site extension transform
2015-09-28T21:49:35 StartSection Executing InsertIfMissing (transform line 4, 16)
2015-09-28T21:49:35 on /configuration/system.webServer/proxy
2015-09-28T21:49:35 Applying to 'system.webServer' element (no source line info)
2015-09-28T21:49:35 Inserted 'proxy' element
2015-09-28T21:49:35 EndSection Done executing InsertIfMissing
2015-09-28T21:49:35 StartSection Executing InsertIfMissing (transform line 8, 47)
2015-09-28T21:49:35 on /configuration/system.webServer/rewrite/allowedServerVariables/add
2015-09-28T21:49:35 Applying to 'allowedServerVariables' element (no source line info)
2015-09-28T21:49:35 Inserted 'add' element
2015-09-28T21:49:35 EndSection Done executing InsertIfMissing
2015-09-28T21:49:35 Successful 'D:\home\site\applicationHost.xdt' site extension transform
2015-09-28T21:49:35 sandboxproc.exe complete successfully. Ellapsed = 447.00 ms

@r3plica
Copy link

r3plica commented Oct 22, 2015

Ok, I finally got this working. Holy moly.....this was difficult.
I am putting all my steps into this post (and deleting the older posts)

The first thing to be aware of is you can't test this locally.

You can't use X-Prerender-Token in your server variables because they get transformed into response headers which is no good, we need the request headers.
You can read about it here: http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-20-configuration-reference#Setting_Server_Variables

Your Redirect rule should look like this:

<rule name="SEO" stopProcessing="true">
  <match url="^(?!.*?(\.js|\.css|\.xml|\.html|\.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|\.woff|\.ttf|\.m4v|\.svg|\.torrent))(.*)" ignoreCase="false" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_USER_AGENT}" pattern="baiduspider|facebookexternalhit|twitterbot|googlebot" />
    <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" ignoreCase="false" />
  </conditions>
  <action type="Rewrite" url="http://service.prerender.io/{HTTP_HOST}/{R:0}" appendQueryString="false" />
  <serverVariables>
    <set name="HTTP_X_PRERENDER_TOKEN" value="<your_token>" />
  </serverVariables>
</rule>

When you add this, you will probably get a 500 error when using ?escaped_fragment= in the querystring, this will be because you need to update your applicationHost.xdt which sits in the directory below your wwwroot folder (http://ruslany.net/2014/05/using-azure-web-site-as-a-reverse-proxy/ is a good explanation)

Your applicationHost.xdt should look like this:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />
    <rewrite>
      <allowedServerVariables>
        <add name="HTTP_X_PRERENDER_TOKEN" xdt:Transform="InsertIfMissing" />
      </allowedServerVariables>
    </rewrite>
  </system.webServer>
</configuration>

When you have added the applcationHost.xdt you MUST restart the server (in azure, just click the website and on the bottom click restart).

If you have done everything correctly, in your account on prerender.io you will see no notices asking you to install your key. If you do, then something is wrong.

One final note: If your project is both the WebAPI and an AngularJS application, you will have to split it into two. The routing in WebConfig interferes with your rewrite rules. I have tried everything and the only solution was to separate the.

I hope this helps someone else.

@Swimburger
Copy link

@r3plica I tried out your example, and the notice is finally removed on the prerender site. I did have to put "http" in front of {HTTP_HOST}/{R:0} in order to make it work.

<action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />

The changes were very minor and I don't really understand why the notice is gone now, but the previous code didn't.
Thanks!

@luisbox
Copy link

luisbox commented Dec 5, 2015

Kudos to @r3plica and @Sniels for figuring this out. Took me a while to get it working but eventually got it to work. I think @blowsie needs to update his original web.config code snippet. Thanks guys!

@JT00
Copy link

JT00 commented Feb 5, 2016

I've got an angularjs site running on iis. Got the "You need to install your Prerender token..." to go away, but I get nothing but 504 errors under the crawl stats. This is not an azure site so i'm not sure the applcationHost.xdt configuration is applicable.

  <httpProtocol>
      <customHeaders>
        <add name="X-Prerender-Token" value="<your_token>" />
      </customHeaders>
    </httpProtocol>

    <rewrite>

      <rules>
        <!--# Only proxy the request to Prerender if it's a request for HTML-->


        <rule name="Prerender" stopProcessing="true">
          <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="baiduspider|facebookexternalhit|twitterbot|googlebot" />
            <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" ignoreCase="false" />
          </conditions>
          <action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}"  appendQueryString="false" />
          <serverVariables>
            <set name="HTTP_X_PRERENDER_TOKEN" value="<your_token>" />
          </serverVariables>
        </rule>

        <rule name="Main Rule" 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="/" />
        </rule>
      </rules>
    </rewrite>

@deadmann
Copy link

deadmann commented Mar 7, 2016

This worked for us. Our rewrite is as follows:

    <rule name="Seo rewrite rule" stopProcessing="true">
      <serverVariables>
        <set name="HTTP_X_PRERENDER_TOKEN" value="[...your token...]" />
      </serverVariables>
      <conditions>
        <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
      </conditions>
      <action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
    </rule>

As far as the "allowableServerVariables", we handled this through the IIS and clicking either the Default Web Site of the Site itself, then clicking the URL Rewrite module icon, then select View Server Variables, and add the HTTP_X_PRERENDER_TOKEN variable name to the list.

With this in place, we were now able to append the escaped_fragment querystring to our urls and see the rewritten results after coming back through the server. You should also be able to verify in your Account page on PreRender.io that the pages are being cached.

HTH,
Randy

it worked for me just fine, but when i add this:

from Snail answer, it stop working...

@timricker
Copy link

@JT00 did you end up getting it to work? I too am not on Azure.

@timricker
Copy link

Incase anyone was also not using Azure and hitting constant 404 errors after setting everything up as per the suggestions above, I was able to get it working by installing the IIS ARR Module, then going into the IIS Rewrite rules for my site in IIS itself and when attempting to add a rule of type "Reverse Proxy Rule", it asked me if I wanted to enable reverse proxy, clicked yes. You dont need to actually add a rule, as now the ARR reverse proxy feature is installed.

More info on this solution here:
http://stackoverflow.com/questions/8281826/url-rewrite-causing-404
http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis

@adaam2
Copy link

adaam2 commented Jun 21, 2016

For those of you who struggled for a long time to get the reverse proxy element of this working and still couldn't figure it out, I opted for the "poor man's solution" using a web request to retrieve the compiled HTML from the hosted prerender.io service

n.b. You CAN test this method locally and it will work :)

Web config rewrite rule:

<rewrite>
      <rules>
        <clear />
        <rule name="Prerender" enabled="true" stopProcessing="true">
          <match url="^(?!.*?(\.js|\.css|\.xml|\.html|\.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|\.woff|\.ttf|\.m4v|\.svg|\.torrent))(.*)" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_USER_AGENT}" pattern="baiduspider|facebookexternalhit|twitterbot|googlebot" />
            <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" ignoreCase="false" />
          </conditions>
          <!-- Rewrite the URL to a controller in our application that will do all of the prerendering legwork -->
          <action type="Rewrite" url="/Home/Snapshot?path={REQUEST_URI}" appendQueryString="false" />
        </rule>
        <rule name="angularjs" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
    </rules>
</rewrite>

Then in a controller of your choice (I opted for Home), create a new Snapshot action as below:

public ActionResult Snapshot(string path)
{
    string fullUrl = default(string);
    string host = "https://example.com"; // CHANGE THIS or use Request.Url.Host
    fullUrl = string.Format("{0}{1}", host, path);

    string prerenderIoUrl = string.Format("{0}{1}", "http://service.prerender.io/", fullUrl);

    string prerenderIoApiKey = "[YOUR TOKEN HERE]";

    var request = WebRequest.Create(prerenderIoUrl);
    request.Headers.Add("X-Prerender-Token", prerenderIoApiKey);

    var response = request.GetResponse();
    var responseStream = response.GetResponseStream();
    var reader = new StreamReader(responseStream);
    string html = reader.ReadToEnd();

    reader.Close();
    response.Close();
    return Content(html);            
}

Ensure you have put your Prerender token and host values into the code above.

Test by changing your user agent in Chrome dev tools to googlebot and appending ?_escaped_fragment_= onto the URL of your site. When you right click and view "Page Source", it should have fully rendered your HTML between your ng-view tags. Also you can use Fiddler to see the outgoing request to the service.prerender.io url.

Have verified that this method is hitting my Prerender.io account and new pages are cached and previously cached pages are hit.

@ktriple
Copy link

ktriple commented Jul 1, 2019

If anyone ever encounters this issue, I've tried the stuff above and got it working after many hours by mixing some things up.

1. In your Web App root directory (/site/wwwroot), add or update your web.config file with this:

<configuration>
  <system.webServer>     
    <rewrite>     
        <rules>
            <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="bingbot|googlebot|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator" />
                </conditions>
                <action type="Rewrite" url="https://service.prerender.io/https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

  </system.webServer>
</configuration>

2. In /site/ create a file named applicationHost.xdt and add this content:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.webServer>
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />
        <rewrite>
            <allowedServerVariables>
                <add name="HTTP_X_PRERENDER_TOKEN" xdt:Transform="InsertIfMissing" />
            </allowedServerVariables>
        </rewrite>
    </system.webServer>
</configuration>

**3. Restart your Web App service (click 'Stop' and 'Start', not only 'Restart').

4. Test with a tool like: https://technicalseo.com/tools/fetch-render/

Hope this helps someone.

@masanchezro
Copy link

masanchezro commented Sep 6, 2021

This worked for us. Our rewrite is as follows:

        <rule name="Seo rewrite rule" stopProcessing="true">
          <serverVariables>
            <set name="HTTP_X_PRERENDER_TOKEN" value="[...your token...]" />
          </serverVariables>
          <conditions>
            <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
          </conditions>
          <action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
        </rule>

As far as the "allowableServerVariables", we handled this through the IIS and clicking either the Default Web Site of the Site itself, then clicking the URL Rewrite module icon, then select View Server Variables, and add the HTTP_X_PRERENDER_TOKEN variable name to the list.

With this in place, we were now able to append the escaped_fragment querystring to our urls and see the rewritten results after coming back through the server. You should also be able to verify in your Account page on PreRender.io that the pages are being cached.

HTH,
Randy

Hi!!

I spend a lot days for the solution, but i add the variable and works fine!!!

Solution for me :

Only exist the web.config with the configuration (Htm5 redirect and this) , i dont need it applicationHos.xdt.:


<rewrite>
          <rules>
              <!--# Only proxy the request to Prerender if it's a request for HTML-->
              <rule name="SEO" stopProcessing="true">
              <match url="^(?!.*?(\.js|\.css|\.xml|\.html|\.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|\.woff|\.ttf|\.m4v|\.svg|\.torrent))(.*)" ignoreCase="false" />
              <conditions logicalGrouping="MatchAny">
                  <add input="{HTTP_USER_AGENT}" pattern="facebookexternalhit|twitterbot|googlebot|whatsapp" />
                  <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" ignoreCase="false" />
              </conditions>
                  <action type="Rewrite" url="http://service.prerender.io/http://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" /> 
              <serverVariables>
                <set name="HTTP_X_PRERENDER_TOKEN" value="yourtoken" /> 
              </serverVariables>
              </rule>
              <rule name="Redirect To Index" stopProcessing="true">
                  <match url=".*" />
                  <conditions>
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                  </conditions>
                  <action type="Rewrite" url="/" />
              </rule> 
          </rules>
      </rewrite>

The next step was as you indicates ; add into Rewrite module icon, then select View Server Variables, the new variable name "HTTP_X_PRERENDER_TOKEN" and works !! amazing =)!!

Thnks for your time.

I want to share my test options ;

1.-https://technicalseo.com/tools/fetch-render/
2.-https://developers.facebook.com/tools/debug

Any ask or something im here

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