• 0

IIS // URL Rewrite Debacle // Redirecting one domain to two directions (hear me out)


Question

Hey gurus, hope you are all safe and well.

 

I really need the oracles help and guidance here.

 

Scenario

I have a domain (alias.com) which is an alias of a main (website.com) IIS site.  We need:

  • Requests for alias.com to be redirected to website.com
  • Requests for alias.com/string to be redirected to website.com/newlocation/string

 

As I type this, it really hits home as to how simple this sounds but I have been round the mill and still no further on.

 

After many iterations of attempts but here is the logic I am working with:

Rule for redirecting alias.com/string to website.com/newlocation/string

Example:  User browses to alias.com/products and should be redirected to website.com/newlocation/products

	<rule name="Rule 1" enabled="true" stopProcessing="true">
		<match url="(.*)" />
		<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
			<add input="{HTTP_HOST}" matchType="Pattern" pattern="^alias\.com/.+$" ignoreCase="true" negate="false" />
		</conditions>
		<action type="Redirect" url="http://website.com/newlocation/{R:1}" />
	</rule>

Rule for redirecting alias.com to website.com

Example:  User browses to alias.com and should be redirected to website.com

	<rule name="Rule 2" patternSyntax="ECMAScript" stopProcessing="true">
		<match url="(.*)" />
		<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
			<add input="{HTTP_HOST}" pattern="^alias\.com$" />
		</conditions>
		<action type="Redirect" url="http://website.com/" appendQueryString="false" />
	</rule>

 

Any help or advice would be greatly appreciated.

 

Thanks heroes.

1 answer to this question

Recommended Posts

  • 0

Right guys, for anyone that stumbles across this I have the solution in place now.

 

So, I wanted an alias Apex domain (www and non-www) to redirect to the main site URL BUT for any links to subdirectories and subpages of this alias domain to redirect to new location etc. (Example:  www.alias.com/products/item1/neowin-subscription) would be redirected to the main site (website.com/newlocation/products/item1/neowin-subscription).

 

Do the following to achieve this (sorry if this is really basic stuff but syntax held me back for a good few hours so putting this here for people with as much IIS URL Rewrite experience as me):

  • Add bindings for alias.com www.alias.com to your main website URL
  • Open your document root of the main website
  • Create a file called RewriteMaps.config
  • Enter the following and save:
<rewriteMaps>
  <rewriteMap name="MyRedirects">
	<add key="/about-us" value="/newlocation/about-us" />
	<add key="/contact-us" value="/newlocation/contact-us" />
	<add key="/products/item1/neowin-subscription" value="/newlocation/products/item1/neowin-subscription" />
  </rewriteMap>
</rewriteMaps>
  • Add the following to your web.config file:
        <rewrite>
        <rewriteMaps configSource="RewriteMaps.config"></rewriteMaps>
            <rules>
                <clear />
                <rule name="alias.com redirects" enabled="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{MyRedirects:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
  • Restart the website and hopefully you are good to go

Life is too short to be Googling IIS URL Rewrite syntax examples, regular expression options etc.

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I'm still rocking iOS 25.x on my primary phone cuz iOS 26 still has usability quirks (mostly aesthetic and thus its UX) which I don't wanna deal with -- and I've been piloting them with all of these updates on my backup phone, so I'm well aware of its "improvements" since iOS 26 was first released (compared to version 26.5.x).
    • Firefox 152.0.4 is out.
    • Then why are you still here?  
    • Glary Utilities 6.44.0.48 by Razvan Serea Glary Utilities offers numerous powerful and easy-to-use system tools and utilities to fix, speed up, maintain and protect your PC. Glary Utilities allow you to clean common system junk files, as well as invalid registry entries and Internet traces. You can manage and delete browser add-ons, analyze disk space usage and find duplicate files. You can also view and manage installed shell extensions, encrypt your files from unauthorized access and use, split large files into smaller manageable files and then rejoin them. Furthermore, Glary Utilities includes the options to find, fix, or remove broken Windows shortcuts, manage the programs that start at Windows startup and uninstall software. All Glary Utilities tools can be accessed through an eye-pleasing and totally simplistic interface. Glary Utilities 6.44.0.48 changelog: Optimized Context Menu Manager: Improved features based on user feedback. Optimized Wipe Free Space: Optimized the interface display for a better user experience. Minor GUI improvements. Minor bug fixes. Download: Glary Utilities 6.44.0.48 | 27.0 MB (Freeware) Download: Portable Glary Utilities | 32.3 MB View: Glary Utilities Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Reacting Well
      Juan Dela earned a badge
      Reacting Well
    • Week One Done
      Collagen Project earned a badge
      Week One Done
    • Reacting Well
      Wakeen1966 earned a badge
      Reacting Well
    • Rookie
      Almohandis went up a rank
      Rookie
    • Apprentice
      jahara21 went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      514
    2. 2
      +Edouard
      266
    3. 3
      PsYcHoKiLLa
      146
    4. 4
      Steven P.
      96
    5. 5
      macoman
      54
  • Tell a friend

    Love Neowin? Tell a friend!