简体   繁体   中英

assistance with url rewrite rule for an image

I am working with an MVC 4 app running on IIS 7.5. I want to create a rewrite rule but I am not familiar with it so assistance is required.

The following URL will called by my application

/image/[language]/category/[id]-[size]-[priority]_Some+Random+Text.[extension]

I want to rewrite this in to the following as this is where the file will exist on disk.

/image/[language]/category/product/pr_[id]_[size]_[priority].[extension]

Any ideas of the rule I could use to achieve this?

URL Rewrite in IIS will accept RegEx rules. I believe the following rule would be appropriate here (YMMV, I can't test it at the moment - you can test it yourself using the 'Test Pattern' button available when editing a rewrite rule in the IIS Manager.

^image/[a-zA-Z]+/category/[a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+[_a-zA-Z\+]\.[a-zA-Z0-9]{,3}

and the rewrite action

images/{R:1}/category/producer/pr_{R:2}_{R:3}_{R:4}.{R:5}

This may be more general than you need (IDs might only be (hexa)decimal, size might only be decimal, etc.) but should give you the general gist of how it should be written.

This reference should provide any other information you need and the syntax for writing the rules directly into a web.config .

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