Question

My rules look like this:

    <rule name="SpecificRedirect1" stopProcessing="true">
      <match url="^home" />
      <action type="Redirect" url="/" redirectType="Permanent" />
    </rule>
    <rule name="SpecificRedirect2" stopProcessing="true">
      <match url="^admin" />
      <action type="Redirect" url="/" redirectType="Permanent" />
    </rule>

I want to add more also pointing to url="/"

Is there a way I can combine the matching to just one line ?

Was it helpful?

Solution 2

Although this answer doesn't exactly match your question, I'm suspecting you did not take into account urls that start with something like homely that will match the rules

Update: Like @Smirnov says below a the pattern could be simplified to ^((home|admin)(/|$))

Hence this Regex should work: ^(((home|admin)/)|((home|admin)$))

It will match paths that are exactly home or admin and have no trailing slash or paths that start with home or admin and have trailing slashes.

You can easily test the rules in: http://regexhero.net/tester (not mine nor am I affiliated with it :). Check the multiline option to test multiple paths.

enter image description here Screenshot 2 from regexhero

So finally the rule should look like:

<match url="^((home|admin)(/|$))" />

OTHER TIPS

Use a pipe as an "OR" operator, like so:

<match url="^home|admin" />

This would match on both mydomain.com/home and mydomain.com/admin.

EDIT

If you want anything starting with home or admin, try this:

<match url="^(admin|home)(.*)" />

This will match /admin/help/whatever.htm or /admin123abc or pretty much anything else that starts with admin or home.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top