How to write Rewrite rule for full URL in web.config? - asp.net

I want to write rewrite rule for full URL like
<rule name="r1" stopProcessing="true">
<match url="abc.com/man/mostpopulararticles/brides.aspx" ignoreCase="true" />
<action type="Redirect" url="abc.com/man.aspx" />
</rule>
is it possible. I have tried but it didn't work for me. Is there any other way to do so. Please help me.

<rule name="r1" stopProcessing="true">
<match url="^man/mostpopulararticles/brides.aspx$"/>
<action type="Redirect" url="abc.com/man.aspx" appendQueryString="false" redirectType="Permanent"/>
</rule>
It will be http:// and abc.com as it is not allowing me to enter the url.
Something like this works in my code.

here is the code worked for me:
<rule name="Uk1" stopProcessing="true">
<match url="^man/mostpopulararticles/brides.aspx" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?abc.co.uk$" />
</conditions>
<action type="Redirect" url="/man.aspx" />
</rule>
Thanks All

Related

ASP.Net - HTTP to HTTPS Rewrite Module Not Working When the Character '&' Exists in the URL String

My URL HTTP to HTTPS rewrite does not work when there is the character '&' in the URL.
A 410 page not found results.
An example that results in a 410 is...
http://curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
OR
http://www.curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
However if the '&' is replaced by 'and' in the above URLs the page loads correctly.
I have two rules to rewrite HTTP to HTTPS. One is where there is a non www and the other if there is a www
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.curtainsmadesimple\.co\.uk$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.curtainsmadesimple.co.uk/{R:1}" />
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Can anyone tell me why I am getting this issue?
Thanks in advance.
It will work I believe. This is working for me.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>

IIS rewrite rule doesn't work

I want to simply to redirect Radio/Play?stationId=124 to station/124 but below configuration doesn't work. Other rules in my configuration works so rewrite modules working.
<rule name="radio-play" stopProcessing="true">
<match url="^Radio/Play?stationId=([0-9]+)" ignoreCase="true" />
<action type="Redirect" url="station/{R:1}" redirectType="Permanent" />
</rule>
What is wrong in the configuration ?
Handling query string parameter is different. Here is correct way.
<rule name="radio-play" stopProcessing="true">
<match url="^radio/play" ignoreCase="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="stationid=(\d+)" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="istasyon/{C:1}" redirectType="Permanent" appendQueryString="false"/>
</rule>

What's wrong with IIS7 rewrite rule

I'm trying to do a simple redirect from the www subdomain to the root domain. After trying many variations, I'm stuck and hoping for help. Feeling sure it's something stupid, but can't see it. Here's the rule I'm using.
<rewrite>
<rules>
<rule name="Redirect to root" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.stitchamerica.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://stitchamerica.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Input greatly appreciated.
This works for me:
<rewrite>
<rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://YOURSITE.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

ASP.Net rewrite rule from one domain to a similar domain

I am trying to write a rewrite rule that will take www.mydomain1.co.uk/* and rewrite to www.mydomain2.co.uk/*
I have the following rule that isn't working as I suspect it gets into a infinite loop.
Can anyone help please
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^mydomain1\.co\.uk/$" />
</conditions>
<action type="Redirect" url="http://www.mydomain10.co.uk/{R:1}" redirectType="Permanent" />
</rule>
try once following code
<rule name="Canonical Host Name">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mydomain1\.co\.uk" />
</conditions>
<action type="Redirect" url="http://www.mydomain10.co.uk/{R:1}" redirectType="Permanent" />
</rule>

redirect example.com to www.example.com with IIS7

I've gone through many suggestions here and on the web, and still am failing to make this work. I currently have the following, but it's not working. All help appreciated!
<rules>
<rule name="www-less redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
Your rule seems fie. Try this one (slightly different) -- works fine for me:
<rule name="CanonicalHostName">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
1) Try moving this rule to the top (make it first rule).
2) Possibly (just possibly) you do not have binding for example.com, only for www.example.com ?

Resources