IIS 8.5 URL Rewrite with web service exceptions - url-rewriting

I have an HTTPS redirect set up in a URL Rewrite. Everything works but I need to exclude some server ports for web services that are not going to be included in the SSL.
<rewrite>
<rules>
<rule name="HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{SERVER_PORT}" pattern="1010" />
<add input="{SERVER_PORT}" pattern="1212" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
When I add the server port exception, the web services work but I don't get my redirect on the http calls.

The solution turned out to be a missing attribute....
<add input="{SERVER_PORT}" pattern="1010" negate="true"\>

Related

web.config Redirect rule not working in IE and FireFox

I have two domains baddomain.com and gooddomain.com which are pointing to the same hosting service. I have bought SSl certificate and now I want to redirect Bad one to the good one which has SSL installed. I wrote these rules and it works on Chrome but not in IE and firefox. Bad domain redirects to https instead of redirecting to good domain. Thanks.
<!--Redirect from bad domain to good one-->
<rule name="BadtoGood" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="baddomain.com" />
</conditions>
<action type="Redirect" url="https://gooddomain.com/{R:0}" redirectType="Permanent" />
</rule>
<!--Force https on good domain -->
<rule name="forceHTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://gooddomain.com/{R:0}" redirectType="Permanent" />
</rule>
The reason was that I had enabled force https through the website control panel and it was overriding the downstream settings in web.config.
In my case this was the path:
Plesk for windows > Websites and domains > Hosting setting

Point subdomain to it folder IIS

There's a way to point all my subdomains to the same name folder, using Windows Server | IIS - Rewrite Rule or Proxy?
Example:
subdomain1.domain.com ----> C:\customers\development\subdomain1
subdomain2.domain.com ----> C:\customers\development\subdomain2
subdomain3.domain.com ----> C:\customers\development\subdomain3
Is it possible do automatically?
I've tryied these web.config rules
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks in advance!
URL rewrite is mainly used to rewrite URL not physical path. So you have to create a web app with root folder C:\customers\development and bind all subdomains to this IIS site. Then modify your rule to
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\.example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/{REQUEST_URI}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Please modify ^(?!www\.)(.*)\example\.com$ to ^(?!www\.)(.*)\.example\.com$.
Finally, you should be point subdomain to subfolder
Besides, if the application in folder domain1/domain2 and domain3 are three independent projects then you need to use sub-application instead of a folder.

Url rewrite rules not redirecting

I have my .net mvc website hosted in liquid web cloud. I wanted to redirect all website users if they enter the following url http://example.com,http://www.example.com,https://example.com
to https://www.example.com ( i.e. consistent url not matter how they enter)
i tried the following code in web.config but no luck.
<rule name="Redirect Non WWW" stopProcessing="true" >
<match url="^(http\.)(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^https://www.example.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://www.example.com/{R:0}" appendQueryString="true" />
</rule>
Domain is already registered as www.example.com and SSL is enabled on the domain.
You have used MatchAll and also set the condition that url should have https to start rediretion! Just change it to having http instead:
incorrect:
<add input="{HTTP_HOST}" pattern="^https://www.example.com$" />
correct:
<add input="{HTTP_HOST}" pattern="^http://www.example.com$" />
Since you're going to force a redirect to use HTTPS, (.*) will match all URLs and you can set the pattern to off.
<rule name="HTTP to HTTPS Redirection" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
Update:
There isn't any problem with method 1, but also adding this for those who visit this post later.
Method 2:
<rule name="HTTP to HTTPS Redirection" enabled="true">
<match url="(.*)" />
<action type="Redirect" url="https://www.example.com/{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>

Http Redirect within web.config using wildcards not working

My need is to tell IIS, within the web.config to ignore some URLs and to send a HttpRedirect to the client.
To do so, I added the following magic into web.config :
<system.webServer>
<httpRedirect enabled="true" httpResponseStatus="Temporary" exactDestination="true">
<add wildcard="*/iac*; " destination="http://someServer.smthg.be/iac$S$Q" />
</httpRedirect>
</system.webServer>
When I try to make a request, to eg ´myserver/iac/john?doe=hello´ I only receive a 404 not found instead of the 302 I expected.
<rewrite>
<rules>
<clear />
<rule name="test" stopProcessing="true">
<match url="^iac/(.*)" />
<action type="Redirect" url="http://someServer.test.be/iac/{R:1}" appendQueryString="true" redirectType="Temporary" />
</rule>
</rules>
</rewrite>

IIS Rewrite rule and going back to non secure http: afterwards

I got a copy of an https rewrite rule so that when certain keywords are in the url it automatically redirects to an https: on a specific port.
However, I would also like something that when I want to logout of the secure area and go back to the non ssl site that it's no longer on https. I have been unsucessful in doing this.
Can someone tell me what I need to do?
Here's the https rule I used.
<rewrite>
<rules>
<rule name="Secure Account Controller" enabled="true" stopProcessing="true">
<match url="^account" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" >
<add input="{HTTPS}" pattern="off"/>
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="https://{C:1}:44300{URL}"/>
</rule>
</rules>
</rewrite>
** UPDATED **
This seems to have done it.. Not sure why the url in the browswer doesn't revert once it's finished.. but when I click on another page in the site... it's showing http
<rule name="Home Controller" enabled="true" stopProcessing="true">
<match url="^home" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" >
<add input="{HTTPS}" pattern="on"/>
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="http://{C:1}:7224{URL}"/>
</rule>
UPDATED ** This seems to have done it.. Not sure why the url in the browser doesn't revert once it's finished.. but when I click on another page in the site... it's showing http

Resources