Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a IIS URL rewrite rule that appends an URL parameter to the URL. The url parameter is hssc. So, any url that is processed through the server, needs that parameter. Keeping in mind that some urls will have their own params already, and other urls won't, and root urls, etc, sometimes it will need to add ?hssc=1 or &hssc= - so, if I have a URL that is as such:

I also want it that the URL should not be hidden (as in a backend rewrite behind the scenes). I need the URL to appear in the URL, so when users copy the URL, or bookmark it, the parameter is there.

I've set the condition to match it \&hssc|\?hssc - now I just need a way to write the URL, so it appears and keeps the part of the original URL that is already there.

share|improve this question

This should do the trick:

<rule name="Add hssc param" stopProcessing="true">
  <match url=".*" />
    <add input="{QUERY_STRING}" pattern="hssc=1" negate="true" />
    <add input="&amp;{QUERY_STRING}" pattern="^(&amp;.+)|^&amp;$" />
  <action type="Redirect" url="http://{HTTP_HOST}/{R:0}?hssc=1{C:1}" appendQueryString="false"  />

That will always prepend the hssc=1 to the beginning of the querystring while preserving the rest of the querystring. It works for all of your examples. I had it prepend rather than append but I assume that it's the same end result.

share|improve this answer
Your solution works with all his examples but wouldn't url="{R:0}?hssc=1{C:1}" be better as it guards against future changes of protocol and host name? – Jamie Kitson Apr 7 at 13:56
@JamieKitson Yes, you're absolutely right. No need to have the protocol and host, in fact it's better not to. The will will be preserved but the protocol won't. – Scott Forsyth - MVP Apr 16 at 16:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.