0

I'm trying to create a regex rule to use on Mautic's web.config since none was provided and i couldn't find any working option.

I got an example from a website which lists this option:

^([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)$

Which works fine with 2 blocks URLs like:

http://example.com/s/dashboard 

but i also need to work with 3 and 4 blocks URLs like:

http://example.com/s/pages/edit/1?_=1457451067112&mauticUserLastActive=1&mauticLastNotificationId=2

I have managed to create a partial working regex:

(\/[a-z0-9_-]+)

But it won't work on web.config, it gives me a 404, what could be the problem ? As you can see i have a "working" example on RegExr

Stephan
  • 41,764
  • 65
  • 238
  • 329
Ariel
  • 911
  • 1
  • 15
  • 40

1 Answers1

0

I did it like this.

    <rules>
        <rule name="Rewrite to index.php">
           <match url="^([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)$" />
           <conditions>
              <add input="{URL}" negate="true" pattern="index.php(.*)" />
           </conditions>
           <action type="Rewrite" url="index.php/{R:1}/{R:2}" />
        </rule>
        <rule name="Rewrite to index.php 2">
            <match url="^([_0-9a-zA-Z-]+)?(\/[_0-9a-zA-Z-]+)?$" ></match>
            <conditions>
                    <add input="{URL}" negate="true" pattern="index.php(.*)" ></add>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" ></add>
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}/{R:2}" ></action>
        </rule>
        <rule name="Rewrite to index.php 3">
            <match url="^([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)$" ></match>
            <conditions>
                    <add input="{URL}" negate="true" pattern="index.php(.*)" ></add>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" ></add>
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}/{R:2}/{R:3}" ></action>
        </rule>
        <rule name="Rewrite to index.php 4">
            <match url="^([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)$" ></match>
            <conditions>
                    <add input="{URL}" negate="true" pattern="index.php(.*)" ></add>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" ></add>
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}/{R:2}/{R:3}/{R:4}" ></action>
        </rule>                     
        <rule name="Rewrite to index.php 5">
            <match url="^([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)$" ></match>
            <conditions>
                    <add input="{URL}" negate="true" pattern="index.php(.*)" ></add>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" ></add>
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}/{R:2}/{R:3}/{R:4}/{R:5}" ></action>
        </rule>                                 
     </rules>

Hope it helps

Rafael Araújo
  • 3,524
  • 1
  • 14
  • 14