IIS redirect any format of traffic hitting a domain to another domain but retain protocol, subdomains and paths/queries

hi

I'm struggling to get IIS to correctly redirect subdomains and paths/queries sent to a new domain name to the existing domain name

I need anything that comes in to folkestone-hythe.gov.uk (whether it's www. pay. selfserve. etc) and whatever the path (/contact, /article/46) to be forwarded to it's shepway.gov.uk twin, including the protocol

so for example:

https://pay.folkestone-hythe.gov.uk should redirect to https://pay.shepway.gov.uk

http://www.folkestone-hythe.gov.uk/article/contact-us should redirect to http://www.shepway.gov.uk/article/contact-us

http://www.folkestone-hythe.gov.uk/webapp/myshepway/index.php?uprn=12345678 should redirect to http://www.shepway.gov.uk/webapp/myshepway/index.php?uprn=12345678

Here's what I have so far. The path (seems) to work but I'm not sure about the protocol or subdomain side

Match URLConditionsAction
LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave_DietzCommented:
To do this with ARR it will likely be easiest to use four rules.

You can use a condition of {HTTPS} to determine if the request came in over a secure channel or not.  I would recommend a set of four rules as follows.

First rule:
Pattern: (.*)
Conditions: {HTTP_HOST} equals pay.folkestone-hythe.gov.uk
                     {HTTPS} equals OFF
Redirect URL: http://pay.shepway.gov.uk/{R:1}
Checkbox checked for 'Append query string'

Second rule:
Pattern: (.*)
Conditions: {HTTP_HOST} equals pay.folkestone-hythe.gov.uk
                     {HTTPS} equals ON
Redirect URL: https://pay.shepway.gov.uk/{R:1}
Checkbox checked for 'Append query string'

Third rule:
Pattern: (.*)
Conditions: {HTTP_HOST} equals www.folkestone-hythe.gov.uk
                     {HTTPS} equals OFF
Redirect URL: http://www.shepway.gov.uk/{R:1}
Checkbox checked for 'Append query string'

Fourth rule:
Pattern: (.*)
Conditions: {HTTP_HOST} equals www.folkestone-hythe.gov.uk
                     {HTTPS} equals ON
Redirect URL: https://www.shepway.gov.uk/{R:1}
Checkbox checked for 'Append query string'

This will maintain your protocols, correct host between 'www' and 'pay', and query string.

If you have any additional hosts (I think you called them sub-domains) besides www.folkestone-hythe.gov.uk
 or pay.folkestone-hythe.gov.uk you can simply add additional pairs of rules to handle those as well.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Perfect, many thanks. Apologies for the delay, just back from a vacation.
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Sorry, just a quick question if I may

I have the following which is working fine for the www. but fails for the pay. would you be able to advise if it's my coding below, or more likely something else within my IIS /Server settings

Thanks, Neil

    <rule name="rewrite 1 - http://www.folkestone-hythe.gov.uk" stopProcessing="true">
	<match url="^(.*)" />
	<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="(www.folkestone-hythe.gov.uk)" />
            <add input="{HTTPS}" pattern="off" ignoreCase="false" />
	</conditions>
	<action type="Redirect" url="https://www.shepway.gov.uk/{R:1}" redirectType="Temporary" />
    </rule> 
    
    <rule name="rewrite 2 - http://pay.folkestone-hythe.gov.uk" stopProcessing="true">
	<match url="^(.*)" />
	<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="(pay.folkestone-hythe.gov.uk)" />
            <add input="{HTTPS}" pattern="off" ignoreCase="false" />
	</conditions>
	<action type="Redirect" url="https://pay.shepway.gov.uk/{R:1}" redirectType="Temporary" />
    </rule>

Open in new window

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Dave_DietzCommented:
It appears that your server or firewall is not configured to allow access to the pay.folkestone-hythe.gov.uk site (and the pay.shepway.gov.uk) over HTTP.  Since that rule is only looking for requests that are not using HTTPS it doesn't trigger and the user doesn't get redirected.  I would suggest removing the {HTTPS} condition on that rule and see if that works better for you.
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Thanks Dave

Just added the HTTPS version and it errors (as the SSL for that domain is not live yet) but you can accept to continue yet it stays as https://pay.folkestone-hythe.gov.uk without re-writing it to https://pay.shepway.gov.uk
Dave_DietzCommented:
Can you post the rules as they are now?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.