Link to home
Start Free TrialLog in
Avatar of Christian de Bellefeuille
Christian de BellefeuilleFlag for Canada

asked on

IIS URL Rewrite to do 2 actions: Set a ServerVariable, then redirect

I've a hard time understanding how URL rewrite work and need your help.

I want to set a server variable "HTTP_BRANDING" to some value, then redirect to another page which is showing ServerVariables to see that value, and all other servervariables values.  

For my test purpose, i've created an entry in my hosts file so client.test.com, test.com, and variables.test.com point to 127.0.0.1.
I've also created the server variable HTTP_BRANDING by clicking "View Server Variables" in IIS.

I've written one rule:
Match Url
  • Requested URL: Matches the pattern
  • Using: Regular expressions
  • Pattern: (.*)
Conditions
  • Logical Grouping: Match All
  • Input: {URL}
  • Type: Matches the patttern
  • ^/$
Server Variables
  • name; HTTP_BRANDING
  • value: "HELLO!"
  • Replace: True
Action
  • Action type: Redirect
  • Append query string: checked
  • Redirect Type: 301

So with this rule, i expect that just by typing "client.test.com", it would be triggered since server variable "URL" only contain "/".

This partially work.  It redirect to the ShowServerVariables, but this page show HTTP_BRANDING, and it's empty, while most other server variables contain some values.

So my question is Why it doesn't get assigned?

Does anyone have a good tutorial about URL Rewrite? (Something taking few minutes to read, not a 400 pages manual.  I don't plan to launch a rocket to the moon with it, just to do this simple task)

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any additional info on this question?

Dan
Avatar of Christian de Bellefeuille

ASKER

Sorry for the long time for my answer.  We changed our approach to avoid the server variables.  It's now working the way we did it.

But to answer your question, this was for test purpose so there was no need to redirect for the moment, but at the end our goal was to redirect, and have the server pass this variable to the other web site, which is hosted on the same server.

I already did the steps you described from 1 to 4a as i've mentionned in the original post.

Your assumption for the foreach loop was correct.  I'm using similar code to display every variables.

The only difference i see with what i did, is removed the redirection.  I'll have to do some other tests but i assume i did something wrong in my regex condition in the rules with the /.