Maria
Maria

Reputation: 760

iis url rewrite user-friendly urls multiple rules conflict and not wokrs

I've been trying to create user-friendly urls but multiple rules seems to conflict.

I need to create it like:

www.example.com/destination/abc

www.example.com/river/cde

With this code:

<rules>
  <rule name="RedirectUserFriendlyURL3" stopProcessing="true">
   <match url="^destination\.php$" />
    <conditions>
      <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
      <add input="{QUERY_STRING}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
  </rule>
  <rule name="RewriteUserFriendlyURL3" stopProcessing="true">
    <match url="^([^/]+)/([^/]+)/?$" />
      <conditions>
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="destination.php?{R:1}={R:2}" />
  </rule>
  <rule name="RedirectUserFriendlyURL4" stopProcessing="true">
     <match url="^river\.php$" />
        <conditions>
          <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
          <add input="{QUERY_STRING}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />
   </conditions>
   <action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
 </rule>
 <rule name="RewriteUserFriendlyURL4" stopProcessing="true">
    <match url="^([^/]+)/([^/]+)/?$" />
       <conditions>
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
       </conditions>
     <action type="Rewrite" url="river.php?{R:1}={R:2}" />
    </rule>
</rules>

The rules above do not work together and both pages redirect to the one that's set in the first rule. So I get the error that $var is undefined and get no result on page, but the url is different.

I get this result I need

www.example.com/destination/abc

www.example.com/river/cde

But somehow it seems to redirect just in 1 rule.

Please any feedback, I checked many same posts but could find a solution

Upvotes: 1

Views: 135

Answers (1)

DopeAt
DopeAt

Reputation: 451

If your query is same with your php filename e.g

river.php?river=abc and destination.php?destination=abc

then you can change your code like this:

<action type="Rewrite" url="{R:1}.php?{R:1}={R:2}" />

So your filename should be same with query_string in url to work

Upvotes: 1

Related Questions