Orchard Hungary is an archive

This site is now an archive. We'll keep it so the content is accessible, but we won't update it anymore. However, we frequently publish Orchard-related news on our other site Orchard Dojo, so be sure to check that out instead. And if you're interested in news about our Orchard development company, Lombiq, check out our website.

How to create a minisite inside your Orchard website

Tags: minisites, Web.Config, routing, URL Rewrite

Suppose you'd like to have a minisite for something like a one-page little website or even a simpler single page app. You want to do something simple but you still want your administrators to be able to edit the minisite's content. Let's see how to do this in Orchard, the simple way.

First of all, we won't create a new tenant because that would be a huge overkill. What we'll do is that we'll simply employ a convention of placing every content under a specific URL and map our minisite to that URL pattern.

Let's call our minisite Orchard Lulz, because we do it for the lulz. Now what do we have to do?

1. Add some content

We'll need some content to display naturally, so let's add the front page of the minisite and set its URL to "lulz/". Notice the trailing slash: normally we don't add trailing slashed like this but here it will be needed (and nobody will see the item under a URL with a trailing slash).

You can also add some further content, just prefix their URLs with "lulz/", e.g. "lulz/blog".

If you'd like to display a menu or other widget on the minisite you have to configure widget layers accordingly, they'll match for the URL "lulz" too. Correspondingly you have to adjust any existing widget layer rule not to be active on your minisite if the rules were too forgiving (like "true" for being active on every page).

2. Set up routing

Such minisites deserve at least a subdomain but probably also an own domain. Set up your domain's DNS config to point the minisite's address to the domain of your site. E.g. if the Orchard site that we create a minisite under is lombiq.com, we set up a CNAME record to point lulz.lombiq.com to lombiq.com.

We also have to set up that every request to the subdomain is caught and re-routed to our minisite's URL accordingly. For this we'll need to add some URL rewrite rules (using the IIS Rewrite Rules module). Add the following block under your Web.config's <system.webServer> tag, or even better, using Web.config transforms to your Web.Release.config (so your custom configs won't mix with Orchard's defaults).

    <rewriteMap name="MapSSL" defaultValue="OFF">
      <add key="ON" value="https://" />
      <add key="OFF" value="http://" />
    <rule name="Lulz redirect" enabled="true">
      <match url="^lulz($|(/.*))" />
        <add input="{HTTP_HOST}" pattern="^lulz.lombiq.com$" negate="true" />
      <action type="Redirect" url="{MapSSL:{HTTPS}}lulz.lombiq.com{R:1}" />
    <rule name="Lulz rewrite" enabled="true" stopProcessing="true">
      <match url="^(Media|Themes|Modules|Core)" negate="true" />
        <add input="{HTTP_HOST}" pattern="^lulz.lombiq.com$" />
      <action type="Rewrite" url="lulz{REQUEST_URI}" appendQueryString="false" />

A couple of things to note here:

  • Everything opened from lulz.lombiq.com/something is rewritten so it actually fetches lombiq.com/lulz/something (with query strings added, don't be mistaken by the appendQueryString being set to false; the query string is part of {REQUEST_URI}.
  • Requests to files under the folder Media, Themes, Modules and Core are working as usual.
  • If users try to open lombiq.com/lulz/something they will be redirected to lulz.lombiq.com/something. This redirection happens with keeping the original protocol (i.e. http or https).

3. Style it

Since now your minisite's content should be reachable under its own (sub)domain with every content working as intended what's left is really just some styling.

You can use the built-in URL Alternates feature in Orchard to override shape templates for your minisite (just turn it on). This will give you alternates for every shape targeted at URLs (as the name suggests), e.g. the minisite will have alternates like Layout-url-lulz (for the Layout shape). Most possibly you'll want to override the Layout and/or the Document shape templates to include custom stylesheets and scripts for your minisite. But if you're using a base theme like Pretty Good Bootstrap Base Theme you'll able to inject your resources by overriding less generic shapes (in the case of PGBBT these would be Resources and Insertions; URL Alternates work for ad-hoc shapes too). These alternates work for the subpages under /lulz too.

That's it, some light-weight minisite we have here. Happy minisiting!


  • azltdanh said Reply

    When I follow this article, the url rewrite working well, but an error occur whenever I use Url.Action or Url.Content:

    [code] Cannot use a leading .. to exit above the top directory.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: Cannot use a leading .. to exit above the top directory.[/code]

    When I try to comment the second rule
    <rule name="Lulz rewrite" enabled="true" stopProcessing="true">
    <match url="^(Media|Themes|Modules|Core)" negate="true" />
    <add input="{HTTP_HOST}" pattern="^lulz.lombiq.com$" />
    <action type="Rewrite" url="lulz{REQUEST_URI}" appendQueryString="false" />

    The site working, but the Layer rule in Widgets not working.

    Could you help me to solve this problem?

  • Piedone said Reply

    That's strange, I think those should work. What do you use as arguments for these methods exactly?

    A workaround BTW would be to just hard-code URLs. Not nice, but such minisites shouldn't have a lot of content any way (and they are often temporary, so no need to think too much about maintainability).

  • azltdanh said Reply

    My scenario is:

    - I have a main site running on domain.com
    - And many mini-site running on domain1.com, domain2.com...
    - All site share the same database, just different by content displayed

    I have try Theme Picker with many different Zones and widgets for each site, but the main site load very slow until I remove all widgets of mini-site (This problem maybe because of layer rule for homepage).

    When I crossed by this article, it seem the right way to go for me. But then I stuck with the error I mention above.

    You could check out the full stack here: http://postimg.org/image/qk5lxiro7/

    Even in The Theme Machine without any custom: ASP._Page_Themes_TheThemeMachine_Views_Branding_cshtml

  • Piedone said Reply

    Hmm, I don't know, pretty much the same works for me.

  • azltdanh said Reply

    I have try with new installation and the same error occurred.

    Could you send me your working sample in zip?

    • dyrgutt said Reply

      Hi azltdanh, did you ever manage to sort this?

      • azltdanh said Reply

        Hi dyrgutt, I am still stuck at this problem. Do you the same as me?