IIS rewrite rule doesn't work - asp.net

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>

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>

Asp.net 301 Redirect With Multiple QueryString Parameters

I have url like
domain.com/posts/id/title
I want to change URL
domain.com/title-xxx-id
id and title querystring parameters. -xxx- is static.
I had used
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^olddomain.com$" />
</conditions>
<action type="Redirect" url="https://newdomain.com/{R:0}"
redirectType="Permanent" />
</rule>
to domain change but now I need url change in same domain and I have two parameters
In the same domain the redirect is even simpler using URLRewrite (2.x). Something like this.
<rule name="friendly" stopProcessing="true">
<match url="^post/(.+)/(.+)$" negate="false" />
<action type="Redirect" url="{R:1}-xxx-{R:2}" appendQueryString="false" />
</rule>
But in fact you need to send title-xxx-id url to a handler to process. You can do it like this (supposing post is the controller you use).
<rule name="friendly1" stopProcessing="true">
<match url="^(.+)-xxx-(\d+)$" negate="false"/>
<action type="Rewrite" url="/post?title={R:1}&id={R:2}" appendQueryString="false"/>
</rule>
In fact, both rules can work together.
<rule name="friendly" stopProcessing="false">
<match url="^post/(.+)/(.+)$" negate="false" />
<action type="Redirect" url="{R:1}-xxx-{R:2}" appendQueryString="false" />
</rule>
<rule name="friendly1" stopProcessing="true">
<match url="^(.+)-xxx-(\d+)$" negate="false"/>
<action type="Rewrite" url="/post?title={R:1}&id={R:2}" appendQueryString="false"/>
</rule>

IIS 7.5 UrlRewrite rule for 301 redirect to lowercase url

I need a Url-rewrite rule to make a 301-redirect to url in lowercase.
For example http://example.com/CurRENcies/USD should become http://example.com/currencies/usd.
I have the following rewrite rule:
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent"/>
</rule>
How can I do this redirects only for GET requests?
Try this:
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="^.*[A-Z]+.*$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="GET" ignoreCase="true" />
</conditions>
<action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent"/>
</rule>

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

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

Permanent redirection in ASP.net

I want to redirect below URL
http://www.abc.com/preview.asp?type=content&id=237#logo
to
http://www.abc.com/preview.aspx#logo
Any idea about rewrite rules like :
<rule name="Home Document" stopProcessing="true">
<match url="^visiting.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^utm_source=invite%2B&utm_medium=Email%2B&utm_campaign=exhibitor$" />
</conditions>
<action type="Redirect" url="http://www.abc.com/visiting.aspx" appendQueryString="false"/>
</rule>
Thanks
You need to add redirectType="Permanent" to generate a 301 status code:
<rule name="Home Document" stopProcessing="true">
<match url="^visiting.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^utm_source=invite%2B&utm_medium=Email%2B&utm_campaign=exhibitor$" />
</conditions>
<action type="Redirect" url="http://www.abc.com/visiting.aspx" appendQueryString="false" redirectType="Permanent"/>
</rule>

Resources