Previous
Left Arrow
Stop your website from being hijacked by another site.
Current Code Entry
Go Back To Code List
[Web.Config]
  • URL Rewrite with 2 URLs that match with one having an extra Query Value

    Article Entry Date: February 8,2026 @ 04:46:05 / Last Updated On: February 8,2026 @ 04:55:58
Not sure how to write this up, so I am going to give it a shot.
You have two nearly identical URLs, except that one has an Extra Query Value.

site.com/Main.asp?Type=User&UN=YourName
&
site.com/Main.asp?Type=User&UN=YourName&WhereAmI=ASP

Now, we want to apply a URL rewrite to these.
site.com/User/YourName
&
site.com/User/YourName/ASP

In our web.config, we will do something like this.
We don't want to have two different URLs for these, since they are in the same area on the website.




Here, we use the same URL; on the second, we apply a different rule name so that we can reuse the same URL Type=User.
We place the Main Rewrite Rule at the bottom of the stack, so it first checks whether there is a reference to the Where Query; if not, we proceed to the Main Rule and activate it.
This keeps it clean and organized and makes everything flow much better.
Now that I have learned this, I will implement it on our Main site, which will be a nightmare to do since it is already live.