Friday, May 6, 2016

Three Tips for Writing URL Rewrite Rules on IIS

#1 - Recycle the AppPool Between Changes
Anytime you make changes to a rule, you need to recycle the AppPool.  Everytime I made changes to our rewrite rules and saved the config, the website would take time to reload, which made me assume the AppPool was recycled.  However, when I started debugging the rule, I noticed that my old rules were still applying, until I manually recycled the AppPool.

#2 - The match URL value is not the same as the REQUEST_URI value
This one bit me hard.  I was matching on a specific url pattern.  I assumed the same pattern applied in the REQUEST_URI.  This is not the case.  Specifically I wanted to ensure I matched on a folder webpath that was at the root of the website, and not somewhere in the middle of a path.  The match url pattern input did not include the first slash.  However the REQUEST_URI parameter does.

#3 - Make use of the IIS Failed Request Tracing Rules
You can get a verbose step-by-step pattern match that is happening in IIS as it processes your URL rewrite rules by enabling this tool.  It definitely helps with showing the exact value that is being matched against each of your patterns.  And if you have multiple conditions that you wanted to match, it will tell you which one is failing.  I took a few screenshots to get a rough idea of what to look for in IIS.



References

1 comment:

  1. What's the best casino in 2021? | DrMCD
    In 2021, we 삼척 출장안마 looked at the best casino bonuses and 통영 출장안마 promos for 여주 출장마사지 all new players, whether it's new players casino, no 정읍 출장마사지 deposit bonus, 아산 출장안마 or a

    ReplyDelete