here is my rule:
<rule name="RedirectHttps04" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^some-url-here$" />
<add input="{HTTPS}" pattern="^off$" />
</conditions>
<action type="Redirect" url="https://www.example.com/some-url-here" />
</rule>
With the above rule I would like to redirect a specific URL to https and keep all the other ones as they are.
So when user goes to:
www.example.com/some-url-here
http://example.com/some-url-here
http://www.example.com/some-url-here
I would like them to be redirected to:
https://www.example.com/some-url-here
But, after going through many versions and options available here - non of them worked, after reading multiple articles I don't see why the rule above doesn't work (doesn't redirect).
I'm using IIS 8.5.96
More info:
{HTTPS} parameter appears to be always "off"
{HTTP} is either "" for http or "off" for https, but even so the rule doesn't work
I have set to redirect to test.html?p={CACHE_URL} and both appears to take me to test.html?p=http://example.com
The only thing I have that works is a rule which appends parameter at the end if it's not appended, a very ugly hack but ensures user ends up on https :/
Related
I have a IIS server running sites using 2 domains with multiple sites on each.
I'm trying to write a url rewrite rule that only affects the one site
The domains is this
*.it.test.com
*.test.com
I have tried this rule but it seems to it do not seem to work - maybe I need a wildcard or something in the domian.
I'm trying to hit the subdomains of it.test.com
<rule name="Redirect to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" ignoreCase="true" matchType="Pattern" pattern="^it.test.com$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Temporary" />
</rule>
A couple of sites names could be this
bb.it.test.com
aa.it.test.com
cc.test.com
As far as I know, if you choose patternSyntax="Wildcard", the {HTTP_HOST} in conditions is also use wildcard to match.
So this is reason why pattern="^it.test.com$" match failed. Wildcard is a special sentence, mainly including (*) and (?). Start with (^) and end with ($) is the usage of regular expressions.
Match fail:
Even you change patternSyntax="regular expressions", it will still fail because of ^. bb.it.test.com is not start with it but bb.
Two solutions.
Use regular expressions and set the pattern="(.*).it.test.com$", but it only match bb.it.test.com aa.it.test.com. pattern="(.*).test.com$" will match both of them.
Still use Wildcard but set the pattern="*.test.com".
I'm having an issue when trying to configure redirections on IIS server. I have a website running in IIS and first of all i'd like to:
redirect all the incoming requests for that site from http->https
redirect all the incoming requests for that site if the URL is for example: https: //abc.org to https ://abc.org/loginpage
I set the first rule as explained here: https://www.ssl.com/how-to/redirect-http-to-https-with-windows-iis-10/
And then set the second rule as explained here: IIS 10 URL redirect from one domain to another
But it's still not working. Tried restarting IIS, restarting app pools, website, clearing browser cache...
Thanks!
You can try to use this URL Rewrite rule:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
</conditions>
<action type="Redirect" url="https://example.com/loginpage" redirectType="Found" />
</rule>
</rules>
</rewrite>
You need to modify example.com to abc.org.
I am new IIS, but came up in a situation where not all of our clients use ssl on their website but there are a few who does. Hence the problem here is that after enabling redirection, when it redirects to ssl enabled pages, it works well but gives ssl warning on non ssl websites.
I want to add some redirect rules which:
1. Redirects with https on the domains only which I allow.
2. Redirects with http only for the sites not in allowed list.
Any help on this would be greatly appreciated.
Thanks,
Rastu.
As lex says, we could use url rewrite's condition to achieve your requirement.You could put this url rewrite rule insdie the web site.
Notice: Condition's HTTP_HOST should set the domain whcih doesn't enable the SSL.
<rules>
<rule name="HTTP to HTTPS on different SSL Port" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^www.domainwithoutusingSSL.com$" negate="true"/>
<add input="{HTTP_HOST}" pattern="^www.domainwithoutusingSSL2.com$" negate="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" />
</rule>
I have an issue which is driving me mad.
I have a project which I set up and enabled SSL (By changing the SSL enabled flag to true in the application properties)
Then I changed the project url in the web properties to the SSL Url (Shown in the image above)
And finally, I added a rewrite rule to my web.config:
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
This was all fine. I was able to debug my application while on the new HTTPS url. The problem is now I have to test it back on HTTP, so I reversed my steps.
First I commented out the rewrite rule, then I changed the Project Url back to the normal http url and clicked "Create Virtual Directory".
And finally I changed the "SSL Enabled" to false.
This is where the problem lies. When I press F5, my browser uses the normal URL (The correct http one) but it redirects to a https url. I can't change it because when I do it just redirects.
It is driving me mad because there is no rule (that I can find) that is redirecting it. I even uncommented my rewrite rule and changed it to this:
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
To for it to use the http url, but it will not.
Can someone please help me?!?
In the end, this was pretty straight forward. I commented out the rewrite rule and then in the project properties, just set the override application root url to the http url while keeping the project url as the https version.
Looking to create a working IIS rewrite (not a redirect) rule to rewrite http{s}://www.client1.com/page1.htm to https://client1.mysite.com/myapp/client1/page1.htm - I just can't get it working. Driving me a little mad.
My main problem is getting the domain name WITHOUT the TLD part returned as an R{x} or C{x} parameter...
Note the client name is in two places in the target url - AND Note that the original url could be client2.com or client3.org or client4.net
This rule will rewrite it for you:
<rules>
<rule name="Rewrite clients domains" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?([a-zA-Z0-9\-\.]+)\.(\w+)$" />
</conditions>
<action type="Rewrite" url="{MapProtocol:{HTTPS}}://{C:2}.mysite.com/myapp/{C:2}/{R:0}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>