简体   繁体   中英

IIS rewrite rule using regex

I need to rewrite my urls in the following fashion:

myapp/green?item=something&item2=nothing&etc...

needs to be rewritten to lose the "/" after myapp and reorder as below with the addition of the "color"

myapp?color=green&item=something&item2=nothing&etc.....

Anybody know how to make a regex pattern to catch and rewrite this in IIS?

What would be even better if I could catch everything after / to ? so that if the link was myapp/blue? it would still catch and and rewrite it as myapp?color=blue

On the app level in IIS create a blank rule with the following parameters:

Pattern:

\/([a-z]*)([\?])

Rewrite URL:

?color={R:1}

EDIT: this is valid if you're passing only this one query string, but if there are more it's best to bind your regex to one of those queries.

see example in this post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM