Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I download the URL Rewrite module for IIS 7. I'm trying to rewrite url of this form: to (get the number and rewrite its modulu by 1000).

I saw that the rewrite module supports regex but I didn't find where to apply mathematical operations (if possible) to the URL.

I'll be glad to get help with this! Thanks :)

url rewrite module link

share|improve this question

migrated from Nov 12 '10 at 7:20

This question came from our site for computer enthusiasts and power users.

Unfortunately out-of-the box it does not have support for that, however you can use a few lines of C# to do that. You can follow the tutorial at:

Basically you would include a rule conceptually like this one:
<rule name="Modulus Rewrite">
<match url="(.*)/([\d+])$" />
<action type="rewrite" url="{R:1}{Modulus:{R:2}}" />

where you capture the URL, but separately the segment with numbers on it, and pass that to the custom provider

And then your code would look something like the one below and you will use a <condition > to

public class ModulusProvider: IRewriteProvider

    public void Initialize(IDictionary<string, string> settings, IRewriteContext rewriteContext)

    public string Rewrite(string value)
        int iVal;
        if (int.TryParse(value, out iVal)) {
            return (iVal % 1000).ToString(CultureInfo.InvariantCulture);
        return String.Empty;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.