Jaggu
Jaggu

Reputation: 6438

Url rewriting not working as expected

I am trying to rewrite the rule so that if no .svc comes in URL it should rewrite and append .svc in URL.

These are my rules:

<rewrite>   
  <rules>
    <rule name="RemoveSVC" stopProcessing="true">
      <match url="localhost/RestApp/Services/([a-zA-Z0-9]*)/(.*)$" />    
      <action type="Rewrite" url="localhost/RestApp/Services/{R:1}.svc/{R:2}" 
              appendQueryString="true" logRewrittenUrl="true" />
    </rule>    
  </rules>
</rewrite>

Can anybody tell me why is this rule not working?

Upvotes: 0

Views: 465

Answers (1)

Kev
Kev

Reputation: 119856

I think you want:

<rewrite>   
  <rules>
    <rule name="RemoveSVC" stopProcessing="true">
      <match url="localhost/RestApp/Services/([a-zA-Z0-9]*)/(.*)" />    
      <action type="Rewrite" url="localhost/RestApp/Services/{R:1}.svc/{R:2}" 
              appendQueryString="true" logRewrittenUrl="true" />
    </rule>    
  </rules>
</rewrite>

Remove the $ sign on the end.

I'd also get rid of the localhost/ part because that would only work on your local dev PC, when you deploy into production it won't be localhost any more:

<match url="RestApp/Services/([a-zA-Z0-9]*)/(.*)" />
<action type="Rewrite" url="RestApp/Services/{R:1}.svc/{R:2}" 
        appendQueryString="true" logRewrittenUrl="true" />

Upvotes: 1

Related Questions