I am trying to redirect a specific page to another page using rewrite rule. However when ever I add the following code in the web config I get 500 internal server error.
<rewrite>
<rules>
<clear />
<rule name="New Rewrite" enabled="true">
<rule name="Redirect" stopProcessing="true">
<match url="http://www.mydomain.com/terms" />
<action type="Redirect" url="http://www.mydomain.com/" redirectType="Permanent"/>
</rule>
</rule>
</rules>
</rewrite>
I do not know much about redirection, however what I am doing is, let's say i have a domain www.mydomain.com
, and if I have a specific url www.mydomain.com/terms
i need to redirect it to home, that is www.mydomain.com
UPDATE
I have changed the rewrite rule as given, still able to access the page terms. The first part adding a www to non www based urls works fine , however not sure what is wrong in second rule.
<rewrite>
<rules>
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\." />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="news redirect" stopProcessing="true">
<match url="/terms" ignoreCase="true"/>
<conditions>
<add input="{HTTP_HOST}" pattern="domain\.com$" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
Try removing the host from the match URL:
<match url="/terms" />