IIS hosted web application works fine with ssl without www, gives 404 error with www - ssl

Good morning.
I have a web application (made with angular if useful) hosted with IIS on a windows server 2016 with certificate (made with Let's Encrypts wacs) that works fine with ssl.
the problem is, if i use www the site not only appear as not safe, but also gives 404 error.
I tried the following rule on web.config to redirect to non www but without success
<rule name="Redirect WWW to non-WWW" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" />
</rule>
I have other rules, thats my complete webconfig file: https://pastebin.com/wRWarfCV

I think https://www.example.com and https://example.com are Different domains. you need to reissue certificate and add http://example.com as primary domain and add other domain http://www.example.com.
More information you can refer to this link: How do I reissue my SSL certificate?.

Related

URL Rewrite Rule: HTTP to HTTPS Not Working in IIS 8 2016 Server: ERR_INVALID_REDIRECT

I installed a godaddy SSL certificate. All these urls work in the browser:
"park.mydomain.com", "http://park.mydomain.com", "https://park.mydomain.com". The first two show unsecured and the last secured. In the bindings I have two entries. One [https park.mydomain.com port 443] and the other is [http park.mydomain.com port 80]. I installed URL rewrite and added a rule from this link: here. Now, if I type the first or the second url the browser says not found ERR_INVALID_REDIRECT. Only the third one that is https:park.mydomain.com works. If I disable the rule all three work again. What is wrong ? Why is it not redirecting ? The 2016 server with IIS is hosted in azure
<rewrite>
<rules>
<rule name="http_https" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_POST}/{R:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
The redirection was setup correctly. The problem was on the type of certificate that I had installed, that was for one domain only.

URL should hit https instead of http

I am running a Windows Server, where i have hosted a site.
Now i have done the Binding with the SSL certificate for the site. But every time i hit the website URL, it goes to http instead of https. Althoough i have binded http & https with the SSL certificate.
Example -
when i try to hit abc.com
it goes http://example.com
instead of
https://example.com
Do i have to do anything more which can help me to fix this issue.
so everytime i try to visit
example.com
i will visit
https://example.com
Do anyone knows a way to fix this issue !
You need to add a redirect to make sure all traffic gets redirected, something like below. Make sure you have the URL rewrite module installed.
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

301 redirect on IIS. Redirect non-www to www

I ought to redirect my website from non-www to www on IIS 6. e.g if I enter domain.com in the url, it has to redirect to www.domain.com for SEO optimization.
I followed the video "http://www.youtube.com/watch?v=PYxabNrIMQ4" for creating my rewrite rule. And I made it as below
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
But it is not working as expected. Help me out to find the solution.
Note:
My Visual studio shows warning like "The element 'system.webServer' has invalid child element 'rewrite'".
I believe it doesn't make any problem.
According to this video you can redirect using the IIS Manager UI. Make sure you have a second site for the non-WWW version, with the same "Location" as the WWW version of your site; when creating it, be sure to specify your non-WWW domain for the "Host Header" field.
After creating it, right-click the site and go to Properties. Disable logging if you're so inclined (probably not needed because you'll be redirecting anyways), then go to the "Home Directory" tab. Now remove the Application by clicking the appropriate "Remove" button, since it's not used for redirection. Next, select the "A redirection to a URL" radio button, be sure to check "The exact URL entered above" and "A permanent redirection for this resource".
Lastly, in the "Redirect to" field, enter your full WWW url followed by $S$Q (i.e. http://www.example.com$S$Q) -- the $S$Q are important to capture any path and query string the client might send, so if the user goes to http://example.com/foo/bar.html they will be appropriately redirected to http://www.example.com/foo/bar.html instead of just http://www.example.com/ . Click Apply and OK, and your redirection should be set!
Does this works ? remember to add in the root web.config
<rules>
<rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" />
</rule>
</rules>

Azure Cloud Service redirect http to https not working (tried answers on many links)

I'm trying to do the 'simple' task of redirecting/rewriting traffic from http to https, I have one endpoint in a CloudService which is correctly configured for SSL.
I've tried many IIS rewrite rules, like the one below, but none are working. I've also tried setting up the rules via remote desktop on the IIS 8 server directly which also doesn't work.
When I enter any tag in the Azure web.config file the rewrite tag has a blue line under it with a message saying it is invalid under <system.webServer> :
<system.webServer>
...
<rewrite>
<rules>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
Any advice is much appreciated.
In order for these rules to work you have to configure both the endpoints - HTTP and HTTPS !!
If you have not configured plain HTTP endpoint on port 80, your server will never be hit by an Internet traffic, so rewrite rules will never trigger.Thus you get the timeout when you try opening the domain over plain HTTP. There is simply no process listening on port 80 when you haven't defined endpoint for it.

https://www.mydomain.com and https://mydomain.com go to different pages

Web Server: IIS 6.0 (ASP.Net 4.0)
I host two sites: one is the main web site and the other is the store site. Each are separate web sites in IIS. Each share the same wildcard SSL certificate. The store site uses a Host Header (store.mydomain.com) to direct traffic to it.
I want it so any URL used without the sub-domain "store" directs the user to the main web site, not the store web site.
The problem I'm experiencing is that the following URL always directs users to the default.aspx page on the store web site:
https://www.mydomain.com
Yet, these URLs correctly go to the main page on the main web site:
http://mydomain.com
http://www.mydomain.com
https://mydomain.com
What's up with the https://www that directs users to different page?
I have added a rewrite rule in the web.config file for both sites but it doesn't have any effect:
<rewrite>
<rules>
<rule name="Consistent Domain" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.mydomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
First, are you sure this is IIS6? The URLRewrite feature is part of IIS7 and would have no effect under IIS6 if present. If this is IIS6 that may well be the answer to your question.
That aside, it is difficult to answer this based on the data given. It is possible that the bindings of the sites is incorrect and resulting in the traffic going to a site you don't expect.