Use subdomain for each blog within default tenant

Topics: Administration
Apr 14, 2011 at 12:59 PM
Edited Apr 14, 2011 at 12:59 PM

I'm not sure if it is currently possible to do this with Orchard:

I want to have a single Orchard instance (not using the multi-tenancy module) which has multiple blogs, i.e. blog1, blog2 and blog3.
By default they would each have a URL in the format of,, etc.
But I want the individual blog URLs to use subdomains, like,, etc.

I know the multi-tenancy module works in this way, where it creates a subdomain for each tenant. But multiple tenants would not be suitable in my case as the same users will be managing all three blogs.

Is there any way I can achieve this?

Apr 14, 2011 at 7:05 PM

It's not that it's impossible, but you'd have to write some code. A home page provider might do the trick.

Apr 15, 2011 at 8:03 AM

Yes, I was thinking to maybe add some URL rewriting code that routes any requests to

Apr 15, 2011 at 9:03 AM

Do you have access to IIS? You could just use URL Rewrite module in the IIS CP.

Apr 16, 2011 at 6:17 PM
Edited Apr 18, 2011 at 10:50 AM

Yes, I have been playing around with URL Rewrite, but I'm not having much luck at the moment.

I created the following inbound rule:


<rule name="Subdomain to Full Domain" stopProcessing="true">
  <match url="(.*)" />
  <action type="Rewrite" url="{C:1}/{R:1}" logRewrittenUrl="true" />
    <add input="{HTTP_HOST}" pattern="^(?!www)([^.]+)\.(.*)$" />


Which rewrites http://<subdomain> to http://<subdomain><subdomain>

But when I try to go to it throws an exception:


[HttpException (0x80004005): Cannot use a leading .. to exit above the top directory.]
   System.Web.Util.UrlPath.ReduceVirtualPath(String path) +11383567
   System.Web.Util.UrlPath.Reduce(String path) +171
   System.Web.VirtualPath.Combine(VirtualPath relativePath) +214
   System.Web.VirtualPathUtility.Combine(String basePath, String relativePath) +158
   System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) +385
   System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath) +149
   System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, 
String protocol, String hostName, String fragment, RouteValueDictionary routeValues, RouteCollection routeCollection,
RequestContext requestContext, Boolean includeImplicitMvcValues) +208 Orchard.UI.Navigation.NavigationManager.GetUrl(String menuItemUrl, RouteValueDictionary routeValueDictionary) in
d:\TeamCity\Projects\Orchard-Default\src\Orchard\UI\Navigation\NavigationManager.cs:52 Orchard.UI.Navigation.NavigationManager.FinishMenu(IEnumerable`1 menuItems) in d:\TeamCity\Projects\Orchard-Default\src\Orchard\UI\Navigation\NavigationManager.cs:37 Orchard.UI.Navigation.MenuFilter.OnResultExecuting(ResultExecutingContext filterContext) in d:\TeamCity\Projects\Orchard-Default\src\Orchard\UI\Navigation\MenuFilter.cs:38 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +70 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976 System.Web.Mvc.Controller.ExecuteCore() +159 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335 System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20 System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54 Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in d:\TeamCity\Projects\Orchard-Default\src\Orchard\Mvc\Routes\ShellRoute.cs:148 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

Has anyone got any ideas on why this isn't working?

Apr 16, 2011 at 6:47 PM

I'm just wondering if you've missed a backslash in your HTTP_HOST condition where you're capturing the subdomain, so it should be:

Failing that; can you look at the rewrite logs to in general check it's rewriting to what you think it is? It sounds like extra dots are somehow ending up at the beginning of the rewritten path.



Apr 18, 2011 at 10:50 AM

No, adding the backslash didn't make a difference.

And the IIS logs show me that it's actually rewriting to the correct URL. If I switch of URL Rewrite and manually go to the rewritten URL it shows the correct page without any errors.

I don't know whether some of the HTTP header variables should be rewritten as well to make it work.

Apr 18, 2011 at 11:49 AM

Ah ... I see what's happening (looking at the exception) - it seems something within Orchard / routing is trying to work out a parent Url based on the original Url; looks like it's whilst generating the navigation. So yes perhaps you could rewrite headers as well so Orchard has no reference to the original, un-rewritten Url; but otherwise it's looking a bit complicated without some heavy code customisation.

I'm wondering, is there a reason you absolutely have to use subdomains here? :)

Apr 20, 2011 at 1:53 PM
Edited Apr 20, 2011 at 1:53 PM

One solution/workaround I have found for my issue is to use the Rewrite Rules module with the following rules:

RewriteCond %{HTTP_HOST} ^$
RewriteCond %{REQUEST_URI} !^/blog1/.*$
RewriteRule ^ /blog1/ [L,P]
Apr 20, 2011 at 5:40 PM

YEAH ;) I was about to suggest it !

It's not a workaround, it's reall a solution. You can even use whatever is provided as the first segment, and reuse the variable on the last one => It can be a redirect or an internal transfer (transparent to the user and to the modules)

Nov 6, 2011 at 12:28 PM
Edited Nov 6, 2011 at 12:48 PM


I created a directory of Media / Catalog and tried to apply the rule, described by the user TomvE, but to no avail. Show you how to write a rule that would get to the directory URL Catalog.


I now use this rule:

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteCond %{HTTP_HOST} !^$

RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE]


I want to use the directory to initialize the Catalog NopCommerce CMS.

Nov 6, 2011 at 6:07 PM

My guess would be:

RewriteCond %{HTTP_HOST} ^$
RewriteCond %{REQUEST_URI} !^/media/catalog/.*$
RewriteRule ^ /media/catalog/ [L,P]
Nov 7, 2011 at 1:38 AM
Edited Nov 8, 2011 at 12:32 PM

I did as you wrote, but received the error message:

The requested URL /index.html was not found on this server.

If, go to the address it all works fine. In order to check the rule, I created a directory «Catalog» test page HTML. If, you have everything working, so I need to send a request provider on this issue.

Jan 22, 2012 at 9:52 AM

I also want to something like to but i want to use any domainname name i want. I want to create separate subdomains for each user profile so for example: the real url must be something like :

Is this possible with only IIS url rewriting?I've searched everywhere for a working rewrite rule but couldn't find it anywhere. What do you guys advise me?

Jan 22, 2012 at 10:00 AM

You can use the Rewrite Rules module as mentioned. Try it with these rules:

RewriteCond %{HTTP_HOST} ^([^.]+)$
RewriteCond %{REQUEST_URI} !^/users/%1/.*$
RewriteRule ^ /users/%1/ [L,P]
Jan 22, 2012 at 10:32 AM
Edited Jan 22, 2012 at 5:37 PM

unfortunately that doesn't work. It just redirects to the homepage instead of the user profile.

I even tried the following examples in iis rewrite rules:

but it still redirect to the homepage. Could it be that orchard does this auto redirecting to the homepage?

Jan 23, 2012 at 8:50 AM

It's something I want to figure out as well, but properly integrated with Orchard instead of using rewrites (so we can write links correctly on the way out too).

The key is using Alias and storing "domain" alongside area/action/controller, but there are some other tricky aspects like getting the system to write absolute Urls instead of relative ones, haven't experimented with this yet. 

Jan 24, 2012 at 7:20 AM

yes that would be very nice if that's nicely integrated. Though i really have to get this working on the current version so do you know any shortcut or thing i have to change to get this working?

Jan 24, 2012 at 11:05 AM

Regarding your rewrite solution; it could well be that Orchard is redirecting. In Settings.txt you can actually put a command-separated list of domains the site will run on, you could try listing your subdomains there. Otherwise, you'll just have to debug when a request comes in to find out if Orchard is redirecting at any point.

Jan 28, 2012 at 9:48 AM
Edited Jan 28, 2012 at 10:30 AM

Ok i found out what the problem was:
Basically i had the same problem as disccussed in topic:

Example: I have a list and the content manager can choose it's own url of a new list item and he doesn't add a trailing slash to the routepart Slug.
This means the page is not accesable with the correct url including a trailing slash. So the url rewriting doesn't work and results in a blank page.

I don't know if this is by design but i think this is a bug. I do think we have get a boolean setting (Backend settings) for swithing automatically adding a trailing slash after all url's so we don't have this problem anymore. Maybe something for Autoroute? Or just making sure that a url with a trailing slash results in the same page as not trailing slash. Then you create this behavior your self using url rewriting.

Jan 28, 2012 at 6:46 PM

The solution from the linked thread should work for you too;  try the iis rewrite module with the rule to automatically rewrite url's to not include the trailing slash.

Jan 29, 2012 at 6:10 AM

yes but the problem is that i want to have trailing slashed and it's not mandatory for the routepart. so when i automatically add slashed to the browsed url's the content items doesn't get reached when they don't have a trailing slash. Maybe i can automatically add a trailing slash when a users save a routepartrecord.

Jan 29, 2012 at 2:54 PM

Why do you need the trailing slashes? 

Jan 29, 2012 at 4:42 PM

yes well personal preference but that's not the point. The think is that a url with or without a trailing slash has to result in the same page result but isn't the case in at the moment (v1.3).

Jan 30, 2012 at 3:39 PM

I'm sure I've seen a comment from Bertrand or Sebastien about this before, might already be a workitem.

Yes, this is certainly an area where things should be consistent. Whichever one is chosen, there should be a "MOVED" HTTP status and redirect to the correct version, we don't want search engines confused over multiple versions.

I can see how it's an aesthetic choice; however personally I think without the slash is better, not for any SEO or other technical reason, simply that it's one less character and therefore looks simpler.

Actually there is a technical reason: having a slash at the end implies that you are viewing a directory. Since what you're serving is HTML content, the slash could be considered semantically incorrect. See this discussion: (short version: Google recommend non-slashed, but they also state it won't affect search results...)

Jan 30, 2012 at 4:40 PM
Edited Jan 30, 2012 at 4:40 PM

EDIT: I meant to paste this link, might help you accomplish the rewrite rule: 

Znowman, either way, you can accomplish what you want using the IIS Rewrite 2.0 module. You can enforce either *always* have trailing slash, or to never use it. I believe it will do 301 redirect to the version  you decide is canonical. 

I agree with randompete, and I think most developers I've seen talk about this agree too, that the version without the trailing slash is "nicer". It is a matter of choice in the end. 

I also agree that it would be nice for Orchard's routing system to treat them the same, but I don't know enough to know whether or not there is a problem with this. Perhaps it is a valid assumption on Orchard's part that with/without should be treated as separate URL's? Even if Orchard treated them the same, you would want to take measures to attribute the search engine ranking to a single canonical URL (either with/without trailing slash, according to your preferences). Either by using IIS Rewrite to 301 redirect to the canonical version, or using a rel canonical meta tag to tell the search engine the canonical URL for the current page. 

Jan 31, 2012 at 4:38 PM
Edited Jan 31, 2012 at 4:38 PM

for the ones that are interested in my solution, here it is:

RewriteCond %{REQUEST_URI} !^/users/.*$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.local
RewriteRule ^/(.*) /users/%1/$1 [NC]
RewriteRule ^(.+[^/])/$ $1 [P]