Using ARR and URL Rewrite on IIS 10 but keeping trailing information - redirect

Hopefully someone can help here as I am struggling with the Regex for the rule. I have ARR installed on IIS and can do a test redirect for say www.example.com/github --> github.com and that works fine.
What I need to achieve is the following:-
http(s)://subdomain.example.com/course/course1/contents/465e5aa
to redirect to
example.externaldomain.com/course/course1/contents/465e5aa
It has to preserve the trailing information after the .com for all requests which will be created on the external site.
I feel totally stumped by the Regex needed for this.
I am happy for the redirected name to appear in the browser bar if that is easier.

OK so I did get this working using a slightly different approach, welcome any comments as to whether this is a good way or not.
I created a new site in IIS for subdomain.example.com, created a web.config with the following:-
<rule name="Subdomain redirection" stopProcessing="true" enabled="true">
<match url="(.*)" ignoreCase="true" />
<action type="Redirect" url="https://example.externalsite.com/{R:1}" redirectType="Permanent" />
</rule>
This got me round trying to get the Regex right for subdomain.example.com in the match url in the main site example.com in IIS. Bit of a cheat I guess :-)

Related

What is wrong with this rewrite rule

I am attempting to create a redirect rule to direct all traffic to one of my pages on my old site to my new site. I have created this rules in the parent web.config on my old IIS server:
<rule name="redirect to survey domain" stopProcessing="true">
<match url="takesurvey" />
<conditions>
<add input="{HTTPS}" pattern="^emory.zanek.net$" />
</conditions>
<action type="Redirect" url="https://survey.zanek.net/{R:1}" redirectType="Temporary" />
</rule>
Essentially I want to redirect all traffic for the specific page takesurvey to a new survey domain. So if the user navigates to:
https://emory.zanek.net/goalw4/takesurvey.aspx?id=fasidisdf
it should redirect to:
https://survey.zanek.net?id=fasidisdf
However, When I applied the rule, and then I navigate to https://emory.zanek.net/goalw4/takesurvey.aspx?id=fasidisdf, it just hangs forever. What am I missing here?
You are specifying {HTTP_HOST} but both of your URLs are HTTPS which operates on a different TCP protocol.
For your simple scenario I would just change {HTTP_HOST} to {HTTPS} in your input line.
For more information about this and robust ways to implement more complex/multiple cross types, see the link below.
Web config rewrite HTTPS

IIS 10 URL redirect from one domain to another

I would like to redirect a specific site from one domain to another and i have tried the following URL redirect. Not sure where i am going wrong.
I have an app at http://www.a.b.com/myapp/index.aspx
I would like to redirect it to
http://www.a.c.com/myapp/index.aspx
<rule name="testredirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^myapp/index.aspx$" />
<action type="Redirect" url="http://www.a.c.com/{R:0}" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.a.b.com$" />
</conditions>
</rule>
The rule work perfectly on my side. Please try to clean browser cache and post your detailed error message. Please ensure you are running the rule in the right place and has been enabled.
Besides, please check whether the incoming request is reaching the correct application pool.

web.config rewrite rule not working after adding similar match URL expression

i am trying to implement following URL rewrite rule in my web.config. The rule i have mentioned below is working fine, the problem is when i add one more valid expression let say |news/Announces-Magento-Partnership to it, site stops working and it give 500 internal server error, i tried making another rule but it is still not working.
<match url="^es/(news/Announces-Autodesk-Forge-Partnership|news/completes-sas-70-certification|news/becomes-oracle-gold-level-partner|news/continues-global-expansion|news/breaks-ground-on-new-headquarters|news/onboards-nine-new-team-members|news/best-places-to-work-2018-honoree|news/101-best-and-brightest-2017|news/2018-healthiest-employers|news/techgateway-day-2017-broward-county|news/best-custom-business-software-developer-2017|news/2018-best-bespoke-software-development-firm|news/reviewed-fastest-growing-tech-2017|news/raises-funds-for-victims-of-harvey|news/makes-incs-honor-roll-sixth-time|news/to-exhibit-at-the-2017-nsc-congress-and-expo|news/joins-ellie-mae-pro-consulting-partner-program|news/announces-expansion-increases-us-team-by-5-new-members|news/announce-a-new-director-of-sales-supply-chain-marketing|news/named-to-south-florida-business-journal-2017-top-private-company-list|news/announce-a-new-director-of-sales-enablement|news/to-exhibit-at-nacds-2017-in-san-diego-ca|news/to-exhibit-at-iltacon-2017-in-las-vegas-nv|news/to-exhibit-at-inman-connect-2017-in-san-francisco-ca|news/to-exhibit-at-infoag-2017-in-st-louis-mo|news/to-exhibit-at-avma-2017-in-indianapolis-in|news/to-exhibit-at-mwaa-2017-in-chicago-il|news/to-exhibit-at-wtc-2017-in-las-vegas-nv|news/to-exhibit-at-invest-2017-in-new-york-city-ny|news/to-exhibit-at-igss-2017-in-amsterdam-netherlands|news/to-exhibit-at-hitec-2017-in-toronto-canada|news/to-exhibit-at-infocomm-2017-in-orlando-fl|news/to-exhibit-at-unite-europe-2017-in-amsterdam-netherlands|news/to-exhibit-at-sabre-travel-technology-exchange-2017-in-las-vega-nv|news/to-exhibit-at-ncsc-2017-in-washington-dc|news/to-recieve-healthiest-employer-award|news/to-exhibit-at-naa-2017-in-atlanta-ga|news/to-exhibit-at-ala-2017-in-chicago-il|news/to-exhibit-at-iste-2017-in-san-antonio-tx|news/to-exhibit-at-hci-2017-in-boston-ma|news/to-exhibit-at-money2020-in-copenhagen-denmark|news/to-exhibit-at-irce-2017-in-chicago-il|news/to-exhibit-at-safety-2017-in-denver-co|news/to-exhibit-at-e3-2017-in-los-angeles-ca|news/to-exhibit-at-cfma-conference-in-phoenix-az)(.*)" />
<action type="Rewrite" url="/{R:1}{R:2}" appendQueryString="true" />
</rule>

In IIS 8.5, how do I map a sub-domain to an application within a site?

Currently I have an IIS 8.5 server with a URL of:
subdomain.domain.com/application_instance_name_1
Under a site called Portal Application there are 3 instances of the application, one for each customer.
I would like to create a subdomain per customer and direct it to their version of the application under the Site called Portal Application, for example, Customer 1 would type in:
customer_1_name.domain.com
and in IIS it would be directed to the site and Application below:
Sites/Portal Application/customer_1_application
This is my first time posting on here, I did find something that maybe relevant here but its for Apache not IIS.
IF you need further information please let me know.
Thanks
brian
1) You need to install URL Rewrite and ARR module for IIS
2) Enable ARR. On the Application Request Routing page, select Enable proxy
3) Create rewrite rule
<rewrite>
<rules>
<rule name="rewrite customer_1_name.domain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^customer_1_name.domain.com$" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="http://subdomain.domain.com/Portal Application/customer_1_application/{R:1}" />
</rule>
</rules>
</rewrite>
P.S. You might have problem with your resources(images,styles,css,js). Because your html might contains absolute paths to resources
You can check this post, when author is creating outbound rule for fixing relative urls https://blogs.iis.net/carlosag/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr

Need to get a site redirecting both to www and https

Parts of other answers on Stack Overflow worked, other parts didn't, so I thought I would ask for the full solution including IIS settings re bindings.
I have a site (old ASP classic) that is being moved to IIS 8 (2012).
The site works when testing it from my hosts file.
At the moment I can only get it to redirect http to https not non www requests to www.example.com as well.
So I have 2 bindings in IIS (80/433) for www.example.com, I also tried it with another set without the www. e.g example.com but then I got errors such as the system is trying to process your request in such a way it won't return e.g following redirects around in a circle etc.
I am not so sure if that was about the 2 lots of bindings or the rules it was getting a bit messy then. So I need the whole approach from IIS binding setup and web.config rules (or is there a better way in IIS 8 to force all 80 traffic to port 443?)
I already have a number of ISAPI rules in my web.config file such as
<rule name="Order" stopProcessing="false">
<match url="^applications/order/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="plugins/order.asp" />
</rule>
<rule name="Robots 1" stopProcessing="false">
<match url="^robotstxt\.asp$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="robottxt.asp" />
</rule>
<rule name="Robots 2" stopProcessing="false">
<match url="^robotstxt$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="robottxt.asp" />
</rule>
So when I read up I saw about people trying to to do both rules at once or in two sets but it just never managed to work foe me.
I need non http requests to go to https
and for non www requests to go to www.example.com e.g https://www.example.com
At the moment it's partially working but only because I am not trying the non www. redirects.
I have 2 bindings for the www.example.com hostnames and this one rule at the top.
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
So all the rules are working including the http to https. However I need non www rules to work as well.
To get it to keep the rest of my rules AND to get it to ALSO redirect non www. traffic to www.example.com e.g https://www.example.com. What is the best way to do this.
Do I need another pair of bindings set up without www. e.s example.com for 80/443?
Then, what rules do I add in and what order do they need to be as int .htacces they are processed top to bottom in loops an I just wonder with IIS way there is also a logical path that could trip it over causing infinite loops.
I think adding the include is what I would do if you needed to get on top of this very quickly. Use a search and replace program to add the include tag into all of your pages:
<!--#include file="redirect.asp"-->
Then create the "redirect.asp" with something similar to below:
<%
webDomain=LCase(Request.ServerVariables("HTTP_HOST"))
scriptname=Request.ServerVariables("SCRIPT_NAME")
If InStr(webDomain,"https://www.example.com")=0 Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "https://www.example.com" & scriptname
End If
%>
You may need to tweak that a bit but its the basics of a coded redirect anyway.