IIS rewrite rule to redirect secure.domain.com to www.domain.com - redirect

i have a site that used to use https://secure.example.com for all secure pages, now the entire site needs to be secure so now ANY url is secure under https://www.example.com
But have loads of legacy CMS content that isn't easy to manage so just wanted to put a rule in that ANY link that had https://secure.example.com/url.... rewritten to https://www.example.com/url....

Tried this
<rule name="secure to www" stopProcessing="true">
<match url="https://secure.example.com/(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^(secure)\.example\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>
but if i try this - https://secure.example.com/resp_register.aspx?prod=41&sid=7337826962595
it fails
But this works and diverts to the secure https version
- http://secure.example.com/resp_register.aspx?prod=41&sid=7337826962595

Related

redirection from non-www to www and http to https in IIS

I am trying to redirect from non-www site to www and also from http to https.
Http to https works well, but non-www to www shows a page not found error.
This is my configuration:
<rules>
<clear />
<rule name="non-www to www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
</conditions>
<action type="Rewrite" url="https://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
<rule name="http to https" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
</rules>
What is going on? I have tried several variants for non-www to www, all from sites found in google, but non worked.
Jaime
Copied from the comment with more explanation.
The action should be set to Redirect instead of Rewrite, because you do want search engines to show www links, and then your site must issue 301 redirection to their bots.
Even if you sometimes want Rewrite, the url must be a relative path to the same site. If rewriting to another site (like the one you used above), then ARR is required with proxy mode. Otherwise, IIS naturally returns 404 errors.
However, rewriting does not change URLs in browser address bar, so it also has no effect on search engine bots.
Reference

Redirecting my website to another hostname from http to https

I'm trying to redirect my internal website to another hostname and from http to https.
Which I'm trying to achieve is when the user hits me.aaa.bbb.ccc, it redirects him to https://me-aaa.bbb.ccc
so the hostname is changed to "-" instead of "." and also it is redirected to https.
I'v used http redirect in IIS as well as this rewrite rule
<rewrite>
<rules>
<rule name="Redirect to https">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern=".*" />
</conditions>
<action type="Redirect" url="https://me-aaa.bbb.ccc/{R:0}" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
Can anyone helps me with this please?!

301 Redirect one domain to another using web.config

I have multiple domains pointing to one hosting location.
I wish to establish one of the domains as my main domain and therefore I wish to perform a 301 redirect to this main domain whenever a user accesses my site from a secondary domain.
For example:
www.example.com
This is my main domain. I want all other domains associated with my site to redirect to here.
If a user comes in on:
www.test.com or
www.test.com/anypage
etc.
Then I want the user to be redirected to the example version of that page.
How do I do this using the web.Config file of my application? The reason I ask is that usually my web hosting provider has a tool in their back office that allows me to setup this redirect however, our client has opted for a different hosting provider that do not provide such a tool.
I have attempted to do this redirect using the following code but it doesn't seem to work:
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^test\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}}" redirectType="Permanent" />
</rule>
My application is an Umbraco powered site and so has several system.webServer entries in the web.config file. It may just be the case that I have entered this code in the wrong place but any help here would be greatly appreciated as I am only used to doing 301 redirects in .htaccess files.
This is not really that umbraco related but I think what you want to do is this:
<rewrite>
<rules>
<rule name="redirect" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Match all urls unless the host name part is exactly www.example.com - and redirect those to www.example.com/whatever.

HTTP to HTTPS Redirect - IIS 8.5 not working properly

I've read a number of posts here on SO as well as on the 'net (IIS blogs, etc.). I'm trying to force all connections going from domain.com to www.domain.com and at the same time forcing the request from HTTP to HTTPS.
I'm using this set of rules and rewrites but the only thing happening is that it's redirecting fine but not redirecting to SSL.
<!-- Redirect to HTTPS -->
<rewrite>
<rules>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^mydomain.com$" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://www.mydomain.com/{R:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol" defaultValue="http">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>
What am I doing wrong?
Main blog reference: http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action and this SO post - web.config redirect non-www to www
We faced same issue while redirecting from http to https using URL Rewrite module, But after switching off the require ssl module within IIS did the trick.
Go to SSL Settings of website
Uncheck require SSL checkbox.
Apply settings and Restart iis
Edit: So I found this blog post: http://www.meltedbutter.net/wp/?p=231 and gave it a try and voila! Worked like a charm. Not sure why this worked over the rules posted above but in my case the below is working and successfully taking all non-www traffic and redirecting it to both www and https.
<!-- Redirect to HTTPS -->
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
This is a long shot for some cases but I had deleted my port 80 bindings for the website as I only wanted SSL / port 443. So from what I can tell is Port 80 binding is also needed for the the rewrite to work correctly.
In my case, I did everything #Valien said and lots of other tries but it did not work. finally I found the problem. It was because I was using 2 rules. First rule was rewriting to NodeJs server and the second to redirect http to https. I changed the order and now it is working correctly.
The config with the correct order in case more than 1 rule is applied:
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://mywebsite.com/{R:1}" redirectType="SeeOther" />
</rule>
<rule name="ReverseProxyToLocalhost:3000" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
</rule>
</rules>
</rewrite>

IIS Rewrite instead of redirect from directory

How can I achieve this in IIS:
When I'll write in the browser: www.mydomain.com/mydirectory to go and point to subdomain.domain.com but the url to be like I've written it in my browser (eg.www.mydomain.com/mydirectory )
You can't rewrite a url to a different domain. You'd either have to do a redirect, or you can use an iframe to contain subdomain.domain.com inside of the page you have at www.mydomain.com/mydirectory.
If you want to rewrite subdomain.domain.com to something like domain.com/subdomain, this would be possible since it is the same domain name, here's the rule in web.config:
<rule name="RedirectSubdomain">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).domain.com" />
</conditions>
<action type="Rewrite" url="/{C:1}/{R:0}" />
</rule>