Try Now
More in this section

Forums / Developing with Sitefinity / Url rewriting subdomain to subdirectory?

Url rewriting subdomain to subdirectory?

6 posts, 0 answered
  1. Victor
    Victor avatar
    44 posts
    10 Mar 2009
    09 Jun 2009
    Link to this post
    We have numerous subdomains going to specific pages:

    subdomain1.site.com    ----->  www.site.com/subdomain1
    subdomain2.site.com    ----->  www.site.com/subdomain2

    I tried using advanced url rewriter but it doesn't seem to match the domain name part:


    I am likely doing this wrong so... help?

  2. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    09 Sep 2007
    10 Jun 2009
    Link to this post
    Someone please correct me if I'm wrong, but I don't think URL rewriting gets applied to the domain part of the URL.

    It would probably be better to accomplish your goal with IIS and not Sitefinity/ASP.NET.


    Just setup two new web sites in IIS and have IIS redirect them to the appropriate URL.

    Gabe Sumner
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    19 Oct 2016
    15 Jun 2009
    Link to this post
    Hi Gabe Sumner,

    Although the UrlRewriter works only in the same domain there is an option to achieve this functionality.
    Below, we are creating a CustomCmsHttpModule that inherits from CmsHttpModule and override GetUrl method.The idea is that we should get the original url string instead of the relative path.

    namespace Telerik.Cms.Web 
        public class CustomCmsHttpModule : CmsHttpModule 
            public CustomCmsHttpModule() 
            protected override string GetUrl(HttpContext context) 
                bool changed; 
                // get the  
                string rewritedUrl = AdvancedUrlRewriter.GetRewritedURL(context.Request.Url.OriginalString, out changed); 
                if (changed) 
                    // make redirect because the url is on atnother website. 
                    return rewritedUrl; 
                return string.Empty; 

    After you have succesfully created the module, you should register it in your web.config file - basically you need to replace the default one only in the sections below:

          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
          <add name="Cms" type="Telerik.Cms.Web.CustomCmsHttpModule, App_Code"/> 


        <validation validateIntegratedModeConfiguration="false"/> 
          <remove name="ScriptModule"/> 
          <remove name="Cms"/> 
          <!--<remove name="LibraryModule"/>--> 
          <remove name="RadUploadModule"/> 
          <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
          <add name="Cms" type="Telerik.Cms.Web.CustomCmsHttpModule, App_Code"/> 

    depending on the application pool mode you are using. Finally create your rule in urlrewrites node.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. David
    David avatar
    2 posts
    25 Sep 2012
    17 Oct 2010
    Link to this post
    Hi I believe we need the same functionality as what is being discussed in this thread. I've played with the code a bit and I cannot get it to work as (I think) is intended. When I match my url it is actually redirecting to the <rewrite> rule, which is great, but the browser is showing the <rewrite> url portion in the browser as well, which isn't so great.

    So for example (I'm simplifying below, so this isn't the exact rule I'm using):


    The browser makes the match on the <url> and redirects to <rewrite> url, but doesn't rewrite, so the user's browser will show: http://domain/subdomain/default.aspx.

    Am I missing a step, or was the code only intended as an example of how you override the GetUrl method?

    Any response would be greatly appreciated. A quick response would be even more appreciated as we may need to quickly rework our projects if we can't figure out a way to accommodate this functionality.

    As a side, we will not "own or control" the iis sub-domains and they will exist on a separate server. We can only get a redirect to our SF project folder.
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    18 Oct 2010
    Link to this post
    Hi David,

    Thank you for using our services.

    The UrlRewriter of Sitefinity works only with relative paths. It captures requests made to the application and does not involve matching the Urls to domains. If you wish to have subdomains such as:
    subdomain1.domain.com or
    which is covered by your license agreement you can use the approach in this KB article to setup subomain pages: Domain-Page mapping.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. David
    David avatar
    2 posts
    25 Sep 2012
    19 Oct 2010
    Link to this post
    Thank you so much. That was hugely helpful.
Register for webinar
6 posts, 0 answered