Why Is Url Not The Same As RawUrl On My HttpRequest (Adventures in prerender.io)

6 January 2015

Merry Christmas / Happy New Year! Now that the holiday break is unfortunately over, back into the swing of things and good old hard work.

Working on implementing prerender.io using the rather old (but does-the-job) MVC HttpModule on GitHub; I got it to a stage where prerender.io was working for the home page but no other pages on the site.

A bit of debugging later, I noticed that the Url had the home page url, but the RawUrl contained what I actually wanted (eg /search/terms).

So - why are the values for Url and RawUrl different? The answer: IIS Rewrite Rules.

For Angular HTML5 mode, we need a rewrite back to the homepage - however, this triggers for the prerender.io requests (meaning that we never get to subpages). To fix this, I added in an exclude for when escaped_fragment is encountered:

<conditions logicalGrouping="MatchAll">

    ...

    <add input="{QUERY_STRING}" pattern="_escaped_fragment_" negate="true" />          

</conditions>

Now, requests get sent for all pages, not just the homepage. SEO, here we come (hopefully)!

Tags: prerender.io, MVC, HttpRequest, url

Add a Comment

No Comments