2016-03-08 67 views
0

我想創建一個正則表達式規則使用Mautic的web.config,因爲沒有提供,我找不到任何工作選項。Web.config正則表達式得到網址部分

我接到了一個網站,該網站列出了該選項的例子:

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

與2頁街區的URL一樣正常工作:

http://example.com/s/dashboard 

,但我還需要3首和4個蓋帽工作網址喜歡:

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

我已成功地創建部分工作正則表達式:

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

但它不會在web.config上工作,它給了我一個404,可能是什麼問題?正如你可以看到我有一個「工作」的例子RegExr

回答

0

我是這樣做的。

<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> 

希望它可以幫助