Need to redirect non-www and/or http to www AND https - redirect

Plain asp website. Need to redirect non-www to www AND http to https.
Found another post that was close but doesn't completely work. It works for root entries only but if there is anything beyond the root site name then the redirect does not work at all.
For example --
non-www will redirect properly to https and www
non-http will also redirect properly to https and www
But domain.com/categories.asp?cat=130 will not redirect and will simply stay on the non-https, non-www page.
Any fix for this redirect?
Here is the code that I used:
<rewrite>
<rules>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>

OK -- I added this after my http to https and this works:
--
<rule name="Canonical name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.domain\.com$" />
</conditions>
<action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="Permanent" />
</rule>

Related

redirect non-www to www for an internal page's url

I want to redirect:
domain.co.uk to www.domain.co.uk and
domain.co.uk/contact-us to www.domain.co.uk/contact-us.
I have tried dozen of web.config rules with ECMAScript and Wildcard but first one is done but second one either remain same or redirect to www.domain.co.uk i.e. home page. A example of what is there at the moment is as below:
<rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.co.uk/*" />
</conditions>
<action type="Redirect" url="http://www.domain.co.uk/{C:1}/{R:0}" />
</rule>
This will redirect to the www version while preserving the HTTP and HTTPS protocol:
<rule name="ensurewww" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>

"This website is temporarily unavailable" after trying to redirect from non-www to www (godaddy)

I tried to redirect all my traffic from non-www to www, but it resulted in my non-www page being redirected to a seeminly random IP saying just "This website is temporarily unavailable, please try again later."
It has been about 12 hours where my site has been down. (I expected it working as before until the DNS records were updated) So I am getting a bit worried.
Here is how my redirect settings look like:
DNS settings look like this:
A # Forwarded
A # Forwarded
CNAME www badgag.trafficmanager.net
I also added this in web.config if that is relevant:
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false"/>
</rule>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^badgag.com$" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://www.badgag.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>

web.config force redirect of www to non-www with https

So currently my main domain works fine, if I go to www.domain.com it redirects to https://domain.com
my sub-domains are the issue. I have a wildcard SSL as well for *.domain.com
if I go to www.sub.domain.com, it redirects to https://www.sub.domain.com which has an invalid SSL cert and I am trying to get it to load FROM: www.sub.domain.com to https://sub.domain.com but am having some issues. Godaddy was no help as it seems most of them are "New". Hosting with Plesk unfortunately. Currently what I have for my web.config is:
<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>
Check for domains hosting settings like "preferred domain" and 301 redirect to HTTPS:
If you have no 301 redirect to HTTPS you can just delete this web.config.
Wildcard SSL Certificate cannot work on second level sub-domain when you have installed certificate for first level (for example: level3.level2.level1.domain.com).
You cannot use WWW before your sub-domain. I suggest you to refer my previous answer on the same issue.
https://stackoverflow.com/a/37959152/4649681
Hope this will help.
<rewrite>
<rules>
<clear />
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yourwebsite\.com$" negate="true"></add>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://yourwebsite.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>

redirect https:// to https://www in IIS 8

Suppose I have a site http://www.example.com which was 301 redirect from http://example.com to http://www.example.com.
Now after Google's recent update about using SSL for better rankings, I decided to use SSL.
I am using below code in web.config to 301 redirect to https
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
now its redirecting 301 all requests http://www.example.com and http://example.com to https://www.example.com
but it's not redirecting https://example.com to https://www.example.com
I want to do this for only one canonical version as many SEO authority sites suggested.
If I use Plesk builtin functionality to redirect all non www to www, then it does double redirect.
How can I do this, Please help
Try a second rule to enforce the www, such as:
<rule name="Enforce WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^https://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="https://www.{C:1}" redirectType="Permanent" />
</rule>
The condition you have on your rule will stop it firing for a https request such as https://example.com.
Version #2 Try putting this before your other rule, the stopProcessing should stop it going circular.
<rule name="Enforce WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.com" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>

IIS 8.5 URL Rewrite force redirect http --> https for non www

I am starting with the rewrite module have a problem with a "simple" IIS 8.5 URL Rewrite redirect http --> https for a non www site.
Problem: If the domain matches the action url parameter i always get "http://" and not "https://".
This is my rule:
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I can't post several links so "domain" = crm.test.com. The site with the rewrite rule is bound to "domain"=crm.test.com on port 2080.
I want to redirect "http://" to "https://", but i always get "http://" as location in response:
HTTP/1.1·302·Redirect
Connection:·close
Content-Length:·176
Date:·Thu,·15·Jan·2015·08:21:21·GMT
Location:·http://domain/ <--
Content-Type:·text/html;·charset=UTF-8
Server:·Microsoft-IIS/8.5
X-Powered-By:·ASP.NET
I tried the following action url parameter:
Not working:
"https://{HTTP_HOST}/{R:1}" -> http://domain/
"https://domain/{R:1}" -> http://domain/
"https://{HTTP_HOST}:443/{R:1}" -> http://domain/
"https://{HTTP_HOST}/1" -> http://domain/1/
Working:
"https1://{HTTP_HOST}/{R:1}" -> https1://domain/
"https://{HTTP_HOST}:444/{R:1}" -> https://domain:444/
"https://test.domain.com/{R:1}" -> https://test.domain.com/
"https://www.google.com/{R:1}" -> https://www.google.com/
I found "URL Rewrite on IIS from http to https is not working,", but this doesn't solve my problem.
Did i missed something?
The following works for us:
<rule name="HTTP Redirect to HTTPS" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
O. k., i found the solution - the link translation is caused by a tmg 2010 in front of the iis. The tmg has a bug where the link translation resets the https links to http in case of a 301. Problem an solution are described here:
http://blog.sanibellogic.com/2008/09/default
http://support.microsoft.com/kb/924373
Thanks everybody.
You can also config the redirect domain with or without www using URL rewrite. The SSL cert only include: www FQDN.
web.config example (domain example is: sysadmit.com):
<rewrite>
<rules>
<clear />
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.sysadmit.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Extracted from: http://www.sysadmit.com/2017/05/windows-iis-redirigir-http-https.html