I'm trying to create a url rewrite in IIS. We have installed a SSL cert on the server and need all connections to be HTTPS. The HTTPS rewrite rule seems to be working properly.
The issue we have is that users throughout the organization have bookmarks for the server name. Because of this, they will receive a security warning about the server name not matching the certificate. Example: https://mywebserver/BI/Default.aspx.
I need to rewrite the domain so that they are redirect to https://mywebserver.abcxyz.com/BI/Default.aspx
The current rules that I have created will redirect to HTTPS. It will also rewrite the domain from https://mywebserver/ to https://mywebserver.abcxyz.com.
The problem I have is that it will not work if anything comes after the server name. Example of domain that will not work: http://mywebserver.abcxyz.com/BI/Default.aspx
Any suggestions? This is what I currently have in my web.config.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mywebserver\.abcxyz\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://mywebserver.abcxyz.com/{R:1}" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
Try something like this and do the HTTPS as well so you won't have 2 separate redirects
<rule name="CanonicalHostNameRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mywebserver.com" />
</conditions>
<action type="Redirect" url="https://mywebserver.abcxyz.com/{R:1}" />
</rule>
Related
I am running Drupal 8.7.7 on IIS 10, with Plesk 17.8.11
From the code in web.config I would expect an automatic reroute from http://www.focusonlineperformance.nl to https://www.focusonlineperformance.nl
But instead, I get a 403 forbidden message on Chrome.
I have tried <match url=".*" />
I have tried <add input="{HTTPS}" pattern="^OFF$" />
I have the following script in web.config:
<rule name="Plesk. SSL redirect for #6" patternSyntax="ECMAScript"
stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
<add input="{HTTP_IS_SITEPREVIEW}" pattern="1"
negate="true" />
</conditions>
<serverVariables />
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Thanks for any help!
Use below URL rewrite rule:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
make sure you configure https binding for the site and with the right certificate.
and uncheck "Require SSL" by following below steps:
Open iis manager. select your site.
Double click on SSL setting feature from the middle pane:
Uncheck the require SSL and click on apply.
I am using the Rewrite tool for ASP.NET to redirect from http to hpps. I want to reroute to
https://services.net/ExitInterview/home/about
But currently it is routing to
https://services.net/home/about
Below is my redirect rule:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>`
Can I mix the "HTTP_HOST" text with hard-coded text in the rule string? Or is there another way?
I don't want to hard code the url because it changes with local, staging, and production.
<rule name="HTTP to HTTPS redirect" ="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/ExitInterview/{R:1}"
redirectType="Permanent" />
</rule>
Give this a try
This should do what you want in terms of redirecting to HTTPS from HTTP in a web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<httpRuntime executionTimeout="180" />
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" existingResponse="PassThrough" />
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" 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>
</system.webServer>
</configuration>
I use this exact snippet for a webserver that enforces HTTPS redirection, but that also seems to be pretty close to what you have. Are you sure you have configured the structure of the web.config file correctly? - I remember running into issues when I would leave out something.
I need to have both https and non-www rewrites, while also NOT HARDCODING the domain, since we have numerous servers. This needs to be in the web.config, not in IIS.
I've read numerous articles:
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
http://madskristensen.net/post/url-rewrite-and-the-www-subdomain
how to set asp.net web.config rewrite http to https and www to non-www
The https rewrite works, the non-www does not.
<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>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<!--<add input="{CACHE_URL}" pattern="*://www.*" />-->
<!--<add input="{HTTP_HOST}" pattern="*://www.*" />-->
<add input="{HTTP_HOST}" pattern="^.*www.*" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
// i've also tried
// url="{C:2}/{R:1}"
// url="{C:1}/{C:2}"
</rule>
I tested the regex for ^.*www.* on a regex tester and it was matching www.testing.com but not testing.com - so I would assume the pattern would catch it.
I need the URLs to redirect from:
testing.com ---> https://testing.com
www.testing.com ---> https://testing.com
www.testing.com/xyz/ ---> https://testing.com/xyz/
Was my own issue - there was no DNS for the www, therefore the redirect wouldn't resolve on it's own.
Code used:
<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>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{CACHE_URL}" pattern="*://www.*" />
</conditions>
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
</rule>
Add a "Canonical domain name" rule.
The soulution Rob found works fine as well. Mine seems to be a bit easier IMHO.
I have a scenario where I have two domains pointing to same server one is the primary domain to all sub-sites and then there is secondary domain for each sub-site so what I am trying to do is redirecting the secondary domain to primary domain using web.config file.
For Example: if some one enters www.domain-secondary.com it should redirect to www.domain.com/subsite
update: As per some answers on this question and with some amendments i managed to made it work but apparently it only works if domain doesn't contains any special characters such as æ,ø,å. how can i resolve this issue? Please help
Non-working code which contains special characters
<rule name="Redirect to WWW rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.skivebøligmøntering\.dk$" />
</conditions>
<action type="Redirect" url="http://www.skive.dk/skive-boligmontering/{R:1}" redirectType="Permanent" />
</rule>
Try this one .
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I use a standard web.config file for my projects that are hosted on Windows servers. It takes care of 2 tasks.
It redirects the non-www version of the site to the www version.
It redirects the index file to the root.
See below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="index\.asp(?:l)?" />
<conditions>
<add input="{HTTP_HOST}" pattern="example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/" />
</rule>
<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This works great, except for 1 problem. The index redirect is redirecting all sub-directories to the main, index.
For example:
http://www.example.com/index.asp is redirecting to http://www.example.com like it should.
But, http://www.example.com/about/index.asp is also redirecting to http://www.example.com. I would like it to redirect to http://www.example.com/about/
Any help would be greatly appreciated.
Well, after getting no response here, I posted on various .Net forums and finally got an answer. This rule will fix it:
<rule name="redirect index.asp" stopProcessing="true">
<match url="^(\w*/)?index\.asp" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain\.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" />
</rule>