HTTP to HTTPS on domain hosted in VPS using IIS - iis

I have a domain which has the DNS setting pointing to a VPS.
The VPS has an IIS 10 instance which hosts the simple website using html using bootstrap.
I installed an SSL certificate and added bindings for the https part.
I am able to browse the domain on http and https.
I added the following rule to the web.config:
<system.webServer>
<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}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
However this does not seem to help. I am still able to browse on http.
I tried the following:
Tried installing URL Rewrite but it looks like Windows Server 2016 and IIS 10 does not allow the installation
Tried enabling Requires SSL option.
This shows the website in http without images but with text
The website is properly displayed in https
What am I missing here?

I was installing the wrong URL rewrite.
This article helped me fix the problem with the right links.
Automatic IIS redirect http to https on Windows Server 2016: https://gridscale.io/en/community/tutorials/iis-redirect-http-to-https-windows/

Related

Can an Azure App Service redirect www to non-www?

Is it possible to redirect www to non-www at the azure app service level?
I need this at the app service level and not in the configuration file of my app. I have been able to get http to https working under the tls/ssl blade, but I don't see a way to redirect for www.
Do I need another resource like front door or application manager? I'd like to handle it in the app service itself.
My app server is running a docker container that is using an nginx server. I'm not an expert with nginx, and haven't been able to get the redirect to work in the nginx configuration. Plus, I'd like to set this up in my bicep file.
To rewrite a URL, you need to create a web.config file in your wwwroot folder and put the necessary entries in there, if you don't already have a web.config file for your site.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect requests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://yoursite.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Original answer: https://learn.microsoft.com/en-us/answers/questions/193377/how-to-redirect-in-app-service

Accessing HTTP resource on HTTPS IIS Site with ARR Proxy Setting

I have a https site on IIS requesting resources from a http-only API server(Tomcat). There is no SSL certificate in the backend server. I try to avoid the browser error.
I encountered failure for requesting https/http resources from a https site.
I would like to know if there is any reverse proxy setting with ARR that can resolve this problem?
Is it necessary for the API server has HTTPS?
For instance,
The client application url : https://www.example.com/login
The requesting resource: https://www.example.com:8080/api/login
The working api: http://www.example.com:8080/api/login
I have tried adding the following,but not working
<rule name="web" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Rewrite" url="http://example.com/{R:1}" />
</rule>
Thanks a lot.
ARR can solve this problem.
It is no necessary for api server has HTTPS.
Since I only have IIS and no tomcat server, I cannot completely restore your environment, but most of the settings are on the ARR server, so I can give you a reference.
I add two server into server farm and enable URL rewrite at server level. The URL rewrite rule can rewrite https://test2.com/b.html to http://server1IP/api/b.html or http://server2IP/api/b.html.
<rule name="ARR_farm_loadbalance" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="http://farm/api/{R:0}" />
<conditions>
<add input="{HTTPS}" pattern="On" />
</conditions>
</rule>
It works very well.
If you want to use HTTPS in api server, change it in URL rewrite module.

web.config https redirect for multi-domain hosting

I've got a GoDaddy multi website hosting account and now that I've implemented SSL I want all those domains that have SSL to now redirect to https. GoDaddy says the web.config needs to be modified but they have no examples on how to do this for multiple domains.
I've tried the following code which works for the main domain (domainA) on the hosting account but then it messes up all the URLs for all the other domains hosted on that account. For example http://domainA.com redirects to https://domainA.com but with this code implemented http://domainB.com redirects to https://domainB.com/domainB/ -- domainB being the sub-folder that the other domain files are stored.
<configuration>
<system.webServer>
<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}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Try https://{HTTP_HOST}{REQUEST_URI} in your action.
Also I'd use temporary not permenant redirects while testing. Your browser may cache a bad redirect which can be very frustrating so make sure to clear your cache or use an in-private browser window to test changes.

HTTP to HTTPS redirect issue with iis8.5 and Websphere7

We have applications hosted on WebSphere 7.0 and Jboss EAP7 which is behind IIS 8.5 Web server, we enabled ssl for iis.
our requirement is whenever users access with http it has to be redirected to https, to achieve this we configured rewrite2 module in iis below inbound rule
<rules>
<rule name="http to https" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="SeeOther" />
</rule>
issue :- when i access http://www.example.com/login it redirects to https://www.example.com/sePlugins/iisWASPlugin_http.dll and gives 404 Status code. (only applications hosted websphere)
The problem is that we have a ISAPI Websphere plugin to handle the requests and for some reason URL is getting changed by IIS.
redirect rule works fine for Applications hosted on J BOSS.
Not sure what happened to my registration process but I posted the original answer so reposting again after registering.
I found that specifying {CACHE_URL} in the Redirect Url instead of https://{HTTP_HOST}{REQUEST_URI} worked. so url="{CACHE_URL}"
This is how my rule is defined and it seems to work well.
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" />
</conditions>
<action type="Redirect" url="{CACHE_URL}" />
</rule>
I found that specifying {CACHE_URL} in the Redirect Url instead of https://{HTTP_HOST}{REQUEST_URI} worked. so url="{CACHE_URL}"

Adding Rewrite rule to web.config causes error in IIS console

Hi I have added a http to https redirect to my web.config
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Found" />
</rule>
</rules>
</rewrite>
It is within the as required, in fact it is exactly the same as another iis I have running on another box.
However on this server when I save the config and then check the IIS control panel I get an
"There was an error while performing this operation ... Details: Filename \?D:\site\web.config Error:
and there is no error. When I remove the rewrite from the config everything is fine.
The only difference between this server setup and the one that works is that the broken server website is not in the root or is it the default website.
Has anyone encountered this type of error before?
Thanks
Jon
Very strange, even though i had everything set up in IIS and during the add/remove roles to include the http redirect it still needed this extension adding
http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2
the urlrewrite. I installed that extension and it all started working. Shame the error message couldnt ell me that i was missing the feature.

Resources