I have written a URL rewrite to fix images paths to move to a new location for images however it isn't working.
<rule name="Artist Images" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/images/$" />
</conditions>
<action type="Rewrite" url="https://myserver.blob.core.windows.net/v2/images/" redirectType="Permanent" />
</rule>
The expected behavior is that when a request for an image comes in (http://myserver.com/images/sample.jpg) that the new image location
(https://myserver.blob.core.windows.net/v2/images/sample.jpg) is used.
It is a .net application hosted on Azure. Rule is in the web.config.
Any ideas?
Because your condition is not correct, you are putting sign $ which means end of the string, but this is not correct.
<rule name="Artist Images" stopProcessing="true">
<match url="^images/(.*)$" />
<action type="Rewrite" url="https://myserver.blob.core.windows.net/v2/images/{R:1}" />
</rule>
This is what ended up working but Alexey's answer put us in the right direction.
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_URL}" pattern="/images/(.*)" />
</conditions>
<action type="Redirect" url="https://artistshare.blob.core.windows.net/images/{C:1}" />
</rule>
Related
I need to do a URL redirect for a single page. If the client visits https://example.com/default.aspx I need to send to http://example.com/default.aspx and having little success so far. Can anyone shed some light on the best way to limit restrict which page is directed?
Currently what I have is working, but causes a re-direct loop for the pages I do want to be https.
<rule name="ForceNonHttps" stopProcessing="true">
<match url="(.*)default/(.*)" ignoreCase="true" negate="true" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
The rewrite rule below worked great for me!
<rule name="default.aspx HTTPS to HTTP" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="https://example.com/default.aspx$" />
</conditions>
<action type="Redirect" appendQueryString="false" url="http://example.com/default.aspx" redirectType="Permanent" />
</rule>
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
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 ?
I'm trying to redirect requests that have a query string to a different domain name.
I've got a short url, http://short.url and I want to redirect http://short.url?hello to http://long.url/?hello. So the query string has to be kept by the redirect. To make things more complicated, I would like to rediect http://short.url?hello,hello2 to http://long.url/advanced.aspx/?hello,hello2.
Here is the rule I've got now (only dealing with the first part of my question)
<rewrite>
<rules>
<rule name="test" patternSyntax="ECMAScript" stopProcessing="true">
<match url="~/?\w+" />
<action type="Redirect" url="http://long.url/?{R:0}" redirectType="Found" />
</rule>
</rules>
</rewrite>
However, I am not seeing any redirects. Also, is there a better way to do this? Basically I just want to setup a shortcut to pass queries to a website. These are not meant to be permanent so I'm using redirectType="Found".
In case anyone is looking to do this:
<rules>
<rule name="Basic" patternSyntax="ECMAScript" stopProcessing="true">
<match url="\w*" />
<action type="Redirect" url="http://longurl.com" redirectType="Found" />
<conditions>
<add input="{QUERY_STRING}" pattern="\w+" />
<add input="{QUERY_STRING}" pattern="\," negate="true" />
</conditions>
</rule>
<rule name="Advanced" patternSyntax="ECMAScript" stopProcessing="true">
<match url="\w*" />
<action type="Redirect" url="http://longurl.com/advanced.aspx" redirectType="Found" />
<conditions>
<add input="{QUERY_STRING}" pattern="^\w+(?=\,)" />
</conditions>
</rule>
</rules>
I'm trying to rewrite urls from the form:
https://example.com/about
to the form
http://example.com/about
using IIS7 URL rewriting:
<!-- http:// to https:// rule -->
<rule name="ForceHttpsBilling" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<!-- https:// to http:// rule -->
<rule name="ForceNonHttps" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
I'm at a loss; I've been browsing the web for examples and trying every syntax I can think of. The rewrite rules I specify simply don't appear to work at all for any https requests, as if all the https:// requests are flat out invisible to the rewrite engine.
rules work fine; see answer below.
Turns out that I had port :443 bound to a different website!
The above rewrite rules work fine for http:// to https:// rewriting and vice-versa -- though there might be more optimal or simple ways to do it.
Leaving this question here for future voyagers to find, as I didn't see many good examples of the https:// to http:// rewriting scenario on the web.
This post is a little old, but I wanted to answer. I am using ASP.Net MVC3, and Fabio's answer above didn't work for me. The easiest solution I came up with to handle the https redirect to http, while still allowing valid https pages to request secure content was just to add Whitelist rules above my https/http redirects:
<rule name="WhiteList - content folder" stopProcessing="true">
<match url="^content/"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
<action type="None"/>
</rule>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/billing/" redirectType="SeeOther" />
</rule>
<rule name="ForceNonHttps" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
please first consider binding https to your website for making below redirect module to work is essential (so bind your web app with a self-signed or valid certificate)
final part in web.config to redirect https to http:
<rewrite>
<rules>
<rule name="Force NonHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
if you need the equivalent IIS GUI in rewrite module see below image
source: look tech-net for more detail and step by step guide.
Your solution work, but the problem is: your second instruction kill first instruction for any links is not (.)billing/(.), including your css, js, and images.
You can use this https to http rule:
<rule name="HTTPS to HTTP redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{RequiresSSL:{R:1}}" pattern="(.+)" negate="true" />
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="^(.+)\.(?!aspx)" negate="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}/{R:1}" />
</rule>