I would like to redirect all calls to http://www.domain.com/csp/ to https://secure.doman.com/csp/ using URL rewrite running on IIS 8.5. I would like the URL on the browser to update accordingly. I cannot get it to work.
Below is the section of the web.config file with the rule
<rules>
<rule name="CSP to SSL" enabled="true" stopProcessing="true">
<match url="^http://www.domain.com/csp/(.*)$" />
<conditions>
<add input="{CACHE_URL}" pattern="^http://" />
</conditions>
<action type="Redirect" url="https://secure.domain.com/csp/{R:1}" />
</rule>
</rules>
Thank you.
Thanks to peterviola's reply at http://forums.iis.net/t/1214515.aspx?Change+to+https+and+adjust+domain+if+URL+uses+http+and+matches+a+particular+path I managed to get to the solution I was seeking.
<rule name="csp2HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)csp/(.*$)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="csp2subdomain" enabled="true" stopProcessing="true">
<match url="(.*)csp/(.*$)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.|)domain.com$" />
</conditions>
<action type="Redirect" url="https://secure.domain.com{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
The above solution works. I can't understand why this could not be done using one rule.
Hope this helps.
Related
We have a website with multiples bindings/domains. I need to redirect one of them to HTTPS. I try some rules with URL Rewrite but it doesnt work:
rule name="HTTPS Redirect" stopProcessing="true">
<match url="^www.domain.com$" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" />
</rule>
OR
rule name="HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.domain.com$" />
</conditions>
<action type="Redirect" url="https:www.domain.com" />
</rule>
And doesnt work.
Any advise?
Thanks,
Try to combine these two rules.
rule name="HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.domain.com$"/>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
trying to redirect from https://www.domain.info/cms-cp/login.html to https://www-server2.domain.info/cms-cp/login.html
by using the following code for (URL Rewrite) plugin, but unfortunately not working.
<rule name="Redirect To Web2 Server CMS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^(www.domain.info/cms-cp/login.html)$" />
</conditions>
<action type="Redirect" url="https://www-server2.domain.info/cms-cp/login.html" redirectType="Permanent" />
</rule>
<rule name="Redirect To Server2" patternSyntax="ECMAScript" enabled="true" stopProcessing="true">
<match url="login.html" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.domain\.info$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www-server2.domain.info/cms-cp/login.html" redirectType="Permanent" />
</rule>
{HTTPS} is just a bool value to check whether https has been enabled or not.
So you can apply the rule just like this
<rule name="Redirect To Web2 Server CMS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^on$" />
<add input="{HTTP_HOST}" pattern="www\.domain\.info" />
<add input="{URL}" pattern="^/cms-cp/login.html$" />
</conditions>
<action type="Redirect" url="https://www-server2.domain.info/cms-cp/login.html" />
</rule>
I got a little bit of a complicated problem here. I searched other topics but did not come across a solution.
I have an website-url, say foo.com, and an url called bar.com. They share the same code. Now everything works great, except for the redirecting the URL part. I also do want to let you guys know I've had no experience with URL Rewriting, so keep it simple please.
Foo.com existed first, and got redirected from foo.com to www.foo.com via a CanonicalHostNameRule, redirecting the pattern (.*)to http://www.foo.com/{R1}, which works great for that domain, but not for the bar.com domain.
Below are my full rewrite rules for the website:
And these are my web.config rewrite rules:
<rules>
<clear />
<rule name="LetsEncrypt Rule" stopProcessing="true">
<match url="^\.well-known.*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="CanonicalHostNameRule1" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www.\foo.be$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.{R:2}/{R:1}" />
</rule>
<rule name="Rewrite legacy url's" patternSyntax="ECMAScript">
<match url="^.((?!nl-BE).)+$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" redirectType="Permanent" />
</rule>
<rule name="One homepage - redirect /home/">
<match url="^([a-z][a-z]-[A-Z][A-Z])/home/?" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="{R:1}/" redirectType="Permanent" />
</rule>
<rule name="One homepage - redirect root to language">
<match url="^\d*$" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="/nl-BE/" redirectType="Permanent" />
</rule>
<rule name="Add trailing slash">
<match url="^([^.]*[^/])$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="{R:1}/" redirectType="Permanent" />
</rule>
<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
Can you guys please get me on the right track on how to fix this? This is all to complicated for my small brain. Thanks in advance guys!
you could try below url rewrite rule:
<rule name="Canonical3" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^([a-z0-9]+[.]com)$" />
</conditions>
<action type="Redirect" url="http://www.{C:1}/{R:0}" redirectType="Permanent" />
</rule>
this will work with both the domain name.
I am trying to do a rewrite to redirect the following pages ONLY:
www.example.com/
www.example.com/default.aspx
I want to let all other requests pass through. I know I'm pretty close but I just can't seem to get it perfect. Thanks in advance for any & all help!
Here's what I have so far:
<rewrite>
<rules>
<rule name="Base Redirect" stopProcessing="true">
<match url="" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="shop.example.com" appendQueryString="true" />
</rule>
<rule name="Default.aspx Redirect" stopProcessing="true">
<match url="default.aspx" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="shop.example.com" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Problem is it's sending anything containing default.aspx (/pages/default.aspx, etc) and we don't want to redirect anything but the root level default.aspx.
Felix
Try this (basically adding the "^" character to tell regex to only match when it is at the beginning:
<rule name="Base Redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="http://shop.example.com/" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Default.aspx Redirect" stopProcessing="true">
<match url="^default.aspx" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="http://shop.example.com" appendQueryString="true" redirectType="Permanent" />
</rule>
This seems like it should be such a 101-level question but I cannot get it to work.
I very simply need to set up a url rewrite rule that redirects mydomain.com to www.mydomain.com. That's it. But no matter how I go at it, I get a URL redirect error in my browser.
Below are a few different rule definitions I have tried, one-by-one. As far as I can tell, any should work. But none have. I would be incredibly grateful for any insight.
<rule name="non-www to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
<add input="{HTTP_HOST}" negate="true" pattern="^www.mydomain.com$" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="non-www to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\." negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
</rule>
<rule name="non-www to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
</rule>
In IIS, it's built in as a canonical host redirect. See below to 301 redirect any request from http://example.com to http://www.example.com
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>