Redirect of Sites to Specific domain for /Umbraco access

Hi,

We have a multi site setup going live in a couple of weeks.

I like the primary domain to be the one that the umbraco folder is accessed from

Primary doamin would be http://www.site1.com/umbraco

if say they when to
http://www.site2.com/umbraco or site3.com/umbraco I like it to go to site 1. How can I achieve this with a rewrite rule in the web config.

This is a multi site setup using a single back office instance, we want the site1.com/umbraco as back office access and block it for sites 2 and 3.

Thanks

Here’s a snippet you can put into the web config that looks like it will do what you need. There are other dependencies (like preview) that will need redirecting but you shouldn’t ever hit them without hitting umbraco/ first, so don’t think you would need to worry about them.

<system.webServer>
	<rewrite>
		<rules>
			<rule name="umbraco requests to www.site1.com" stopProcessing="true">
				<!-- match Umbraco URL requests -->
				<match url="umbraco.*" />
				<conditions>
					<!-- If we're not on the site1.com domain... -->
					<add input="{HTTP_HOST}" pattern="^www\.site1\.com" negate="true" />
				</conditions>
				<action type="Redirect" url="https://www.site1.com/{R:0}" />
			</rule>				
		</rules>
	</rewrite>
</system.webServer>

You can read more about the rewrite module and different configuration options in the Microsoft docs

Hi,

It sort of dose what I want but end up with too many redirect message. I think it put me on the right track thank you.

1 Like

You didn’t tag this with an Umbraco version but be aware that surfacecontrollers and umbracoapicontrollers in v13 and below do use /Umbraco in the path as well.

V13

A college and my self where playing with rewrite rules at dinner time and found we created one that did not loop but all we got was a white screen.

As I said we have 3 sites all under the same instance of Umbraco.

I assume with us using AD we need to set up 3 diffrent return URLS based on the site we want to get on tp the back office from.

Our idea was we could use the primary site and the other two could just do a redirect if we when to /umbraco/login.

Guess not.

<match url="^umbraco$" />

Would make it only match domain.com/umbraco and not anything else if that’s all you want (so don’t have to worry about cross dominan surface controller issues.. and you can always annotate your api controllers/surface controllers with custom routes eg [route="api/{controlllername}"] so that they aren’t in the /umbraco/… path.

Also there’s an assumption here that we are on IIS.. and not some linux + kestrel hosting?

It IIS.

I have to have a talk to the other dev about this to see what here thoughts are about putting the extra routing in

We are just over a week from this going live. So may have to wait till it gone live to fix this one.

My setup is as follows, maybe with some tweaking you can achieve your way of redirecting.

Each website has a ‘production’ url which is a subdomain of my companies website.

When a website goes live, i keep the ‘production’ url for serving umbraco.
The live url is www.customer1.com but surfing to www.customer1.com/umbraco will redirect to customer1-prod-url.mycompanywebsite.com/umbraco. Surfing to customer1-prod-url.mycompanywebsite.com with /umbraco will go to the live url (www.customer1.com).

<rewrite>
	<rules>
		<rule name="redirect umbraco" stopProcessing="true">
			<match url="(.*)" />
			<conditions>
				<add input="{HTTP_HOST}" pattern="customer1.com" />
				<add input="{REQUEST_URI}" pattern="(?:\/umbraco(?!\/api)|\/media\/forms)" />
			</conditions>
			<action type="Redirect" url="https://customer1-prod.mycompanywebsite.com/{R:0}" />
		</rule>
		<rule name="redirect production" stopProcessing="true">
			<match url="(.*)"/>
			<conditions logicalGrouping="MatchAll">
				<add input="{HTTP_HOST}" pattern="customer1-prod.mycompanywebsite.com" />
				<add input="{REQUEST_URI}" pattern="^/(?!umbraco).*" />
				<add input="{REQUEST_URI}" pattern="^/(?!sb).*" />
				<add input="{REQUEST_URI}" pattern="^/(?!App_Plugins).*" />
				<add input="{REQUEST_URI}" pattern="^/(?!media/forms).*" />
			</conditions>
			<action type="Redirect" url="https://customer1.com/{R:1}" redirectType="Permanent" />
		</rule>
	</rules>
</rewrite>

In your case you try this:

<rewrite>
	<rules>
		<rule name="redirect umbraco" stopProcessing="true">
			<match url="(.*)" />
			<conditions>
				<add input="{HTTP_HOST}" pattern="site2.com" />
                <add input="{HTTP_HOST}" pattern="site3.com" />
				<add input="{REQUEST_URI}" pattern="(?:\/umbraco(?!\/api)|\/media\/forms)" />
			</conditions>
			<action type="Redirect" url="https://site1.com/{R:0}" />
		</rule>		
	</rules>
</rewrite>