SaaS CMS has officially launched! Learn more now.

Redirect sub-domain to specific folder

Vote:
 

I have a sub-domain pointing to another unrelated server.

I have our main www site located on Episerver dxc servers.  Once our IT department points the subdomain to the IP our www site is on, how do I go about directing that sub-domain to a specific folder?  Also the sub-domain would switch to the www domain at that point.

Any help appreciated.

Thanks

#174979
Feb 08, 2017 22:24
Vote:
 

Hi,

You need to set up URL rewrite rules. The URL Rewrite Module is installed by default in Azure so just add appropriate rewrite rules in your web.config https://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module.

#174982
Edited, Feb 09, 2017 0:28
Vote:
 

Thanks for this Johan.

I just want to make sure the syntax is correct.  Does this look correct?

        <rewrite>
            <rules>
                <rule name="Redirect sub-domain" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*sub.domain.com*" />
                    <action type="Redirect" url="www.domain.com/newpage/" />
                </rule>
            </rules>
        </rewrite>

I used wildcards so it will cover http, https, the subdomain with or without anything after it.

Thanks

#175034
Feb 09, 2017 18:53
Vote:
 

You have to test this, but I'm pretty sure that match url only works on the path and query. I think you have to do something like this:

	<rule name="Redirect subdomain" stopProcessing="false">
		<match url="(.*)" />
		<conditions logicalGrouping="MatchAny">
			<add input="{HTTP_HOST}" pattern=".*sub.domain.com" />
		</conditions>
		<action type="Redirect" url="http://www.domain.com/folder/" redirectType="Permanent" />
	</rule>

Please note that you should use regex if you want to match wildcards.

#175064
Edited, Feb 10, 2017 8:56
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.