+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Home page url redirection

Home page url redirection

28 posts, 0 answered
  1. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    24 Jun 2010
    Link to this post
    Hi,

    I have a website developed with Sitefinity 3.7 Standard Edition SP3. And I've a requirement where if the user types the home page url, the url should display just the domain name and not the home page url. How do I achieve this ? For example, if the user types http://www.mydomain.com/home.aspx, the url bar in the browser should display http://www.mydomain.com and the home page content should be displayed.

    Thanks,
    Saumitra
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Jun 2010
    Link to this post
    Hello Saumitra,

    Login to the back-end and go to the Pages section. There set  a  home page for your website. Then add the highlighted attribute to your web.config

    <cms defaultProvider="Sitefinity" pageExtension=".aspx" siteTemplate="" projectName="MySite" disabled="false" pageEditorUIMode="Overlay" redirectToHomePage="false">


    Regards,
    Ivan Dimitrov
    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
  3. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    24 Jun 2010
    Link to this post
    Hi Ivan,

    I've already done that setting in the web.config after referring to one of the posts on sitefinity forums. And it works in the situation where, when I type http://www.mydomain.com in the browser I get the homepage content displayed without "home.aspx" visible in the url. But here my requirement is that even if the user specifically types "home.aspx" in the url, the browser should still display http://www.mydomain.com without "home.aspx" in the url. It should just knock off "home.aspx" from the url. Is it possible ?

    Hope I'm clear.

    Thanks,
    Saumitra 
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Jun 2010
    Link to this post
    Hello Saumitra,

    You should create a HttpModule and inside BeginRequest you should check the current url and call
    request.Initialize(UrlHelper.HomePage.UrlResolved, true);

    Best wishes,
    Ivan Dimitrov
    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
  5. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    24 Jun 2010
    Link to this post
    Hi Ivan,

    Not pretty clear on this. Could you please elaborate on this ?

    Thanks,
    Saumitra
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Jun 2010
    Link to this post
    Hi Saumitra,

    Here is an example at MSDN.

    Regards,
    Ivan Dimitrov
    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
  7. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    25 Jun 2010
    Link to this post
    Hi Ivan,

    The example at MSDN explains how to create a HTTP module. But as you mentioned, there is no Initialize method for the request object. Do I need to do something else ? Here is my code :
    using System;
    using System.Web;
    using System.Collections
      
    /// <summary>
    /// Summary description for CustomURLRewriter
    /// </summary>
    public class CustomURLRewriter: IHttpModule
    {
        public string ModuleName
        {
            get
            {
                return "CustomURLRewriter";
            }
        }
      
      
    #region IHttpModule Members
      
    public void  Dispose()
    {
    }
      
    public void  Init(HttpApplication context)
    {
        context.BeginRequest +=new EventHandler(context_BeginRequest);
    }
      
    void  context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
      
        if(context.Request.Url.OriginalString.Contains("home.aspx")
        {
            //do something
        }
    }
      
    #endregion
    }

    Thanks,
    Saumitra
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Jun 2010
    Link to this post
    Hello Saumitra,

    You have to get the CmsRequest for the current context inside BeginRequest

    CmsRequest request = GetCmsRequest(context);


    Best wishes,
    Ivan Dimitrov
    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
  9. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    25 Jun 2010
    Link to this post
    Hi Ivan,

    Do I need to extend the CmsHttpModule class instead of IHttpModule interface ? How do I get the GetCmsRequest method ?

    Thanks,
    Saumitra
  10. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    28 Jun 2010
    Link to this post
    Hi,

    Any updates on this ? Awaiting a reply from your end.

    Thanks,
    Saumitra
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Jun 2010
    Link to this post
    Hello Saumitra,

    You could create a custom module which will also handle the requests or extend the built in CmsHttpModule and replace it in the web.config (httpModules or system.webServer/modules section depending on the IIS version you use)

    you have to add

    HttpContext context = ((HttpApplication)sender).Context;
    CmsRequest request = GetCmsRequest(context);

     as suggested in the previous reply to you.

    Regards,
    Ivan Dimitrov
    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
  12. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    28 Jun 2010
    Link to this post
    Hi Ivan,

    Let me put it like this. According to your suggestions I created a HttpModule which extended the built-in CmsHttpModule class. Here is the code:
    using System;
    using System.Web;
    using System.Collections;
    using Telerik.Cms.Web;
      
    /// <summary>
    /// Summary description for CustomURLRewriter
    /// </summary>
    public class CustomURLRewriter: IHttpModule
    {
        public string ModuleName
        {
            get
            {
                return "CustomURLRewriter";
            }
        }
      
      
    #region IHttpModule Members
      
    public void  Dispose()
    {
        throw new NotImplementedException();
    }
      
    public void  Init(HttpApplication context)
    {
        context.BeginRequest +=new EventHandler(context_BeginRequest);
    }
      
    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
      
        if(context.Request.Url.OriginalString.Contains("home.aspx"))
        {
            //
        }
    }
      
    #endregion
    }

    In the begin_request method, i need to call GetCmsRequest(context) method according to your post. But I'm not able to find that method. What I want to know is that do I need to instantiate the CmsRequest class to get this method ? Or is there any other way I can reach this method ? Because according to my knowledge, this is a protected method of the CmsRequest class.

    Thanks,
    Saumitra
  13. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    28 Jun 2010
    Link to this post
    Hi,

    Sorry, posted wrong code in the previous post by mistake. Here is the correct one:
    using System;
    using System.Web;
    using System.Collections;
    using Telerik.Cms.Web;
      
    /// <summary>
    /// Summary description for CustomURLRewriter
    /// </summary>
    public class CustomURLRewriter: CmsHttpModule
    {
        public string ModuleName
        {
            get
            {
                return "CustomURLRewriter";
            }
        }
      
      
    #region IHttpModule Members
      
    public void  Dispose()
    {
        throw new NotImplementedException();
    }
      
    public void  Init(HttpApplication context)
    {
        context.BeginRequest +=new EventHandler(context_BeginRequest);
    }
      
    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
      
        if(context.Request.Url.OriginalString.Contains("home.aspx"))
        {
              
        }
    }
      
    #endregion
    }
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Jun 2010
    Link to this post
    Hello Saumitra,

    Create standard  ASP.NET HttpModule as shown below.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Security;
    using System.Web.Security;
     
     
    /// <summary>
    /// Summary description for HttpModule
    /// </summary>
    public class HttpModule : IHttpModule
    {
        #region IHttpModule Members
     
        public void Dispose(){}

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }
     
        void context_BeginRequest(object sender, EventArgs e)
        {    
            HttpContext context = ((HttpApplication)sender).Context;
            if (context.Request.RawUrl.Contains(Telerik.Cms.Web.UrlHelper.HomePage.UrlResolved))
            {
               // if you use virtual directory you should add it to the Host.
                    // you should not include the home page in the Response.Redirect
                    // you have to redirect only to the host - mydomain.com
                    // because we are setting redirectToHomePage later in the config file.
                context.Response.Redirect(context.Request.Url.Host);
            }
        }
        #endregion
    }

    Register the module after Telerik.Cms.Web.CmsHttpModule

    <add name="Cms" type="Telerik.Cms.Web.CmsHttpModule, Telerik.Cms" />
    <add name="CustomModule" type="HttpModule, App_Code" />

    Set redirectToHomePage="false" for the cms node.

    <cms defaultProvider="Sitefinity" redirectToHomePage="false" .....

    As for the GetCmsRequest you had to call
     new Telerik.Cms.Web.CmsRequest(context.Request.RawUrl);, but this is not necessary anymore. The code above should do the trick .

    I attached a video that shows how the code works.

    Sincerely yours,
    Ivan Dimitrov
    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
  15. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    29 Jun 2010
    Link to this post
    Hi,

    I tried the code that you suggested, but still no results. The only difference is that I've registered "CmsHttpModuleUrlRewrite" in the web.config instead of "CmsHttpModule". The settings are as below :
    <httpModules>
                <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add name="Cms" type="Telerik.Cms.Web.CmsHttpModuleUrlRewrite, Telerik.Cms"/>
          <add name="CustomURLRewriter" type="CustomURLRewriter, App_Code"/>
                <!-- Http Module for extension mappings in Library module.-->
                <!--<add name="LibraryModule" type="Telerik.Libraries.LibraryHttpModule, Telerik.Libraries"/>-->
                <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule, Telerik.Web.UI"/>
            </httpModules>

    Below is the snippet of the code that i've written as per your suggestion :
    using System;
    using System.Web;
    using System.Collections;
    using Telerik.Cms.Web;
      
    /// <summary>
    /// Summary description for CustomURLRewriter
    /// </summary>
    public class CustomURLRewriter: IHttpModule
    {
        public string ModuleName
        {
            get
            {
                return "CustomURLRewriter";
            }
        }
      
      
        #region IHttpModule Members
      
        public void  Dispose()
        {
        }
      
        public void  Init(HttpApplication context)
        {
            context.BeginRequest +=new EventHandler(context_BeginRequest);
        }
      
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
      
            try
            {
                if (context.Request.Url.OriginalString.Contains(UrlHelper.HomePage.UrlResolved))
                {
                    context.Response.Redirect(context.Request.Url.Host);
                }
            }
      
            catch (System.Threading.ThreadAbortException ex)
            {
            }
        }
      
        #endregion
    }

    I also tried placing a breakpoint inside the begin_request event. but the breakpoint does not get hit when I browse "home.aspx". What might be going wrong ?

    Thanks,
    Saumitra
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jun 2010
    Link to this post
    Hi Saumitra,

    Most probably you have not registered the module in the right place. This article explains how to register an HttpModule depending on the IIS version - msdn.microsoft.com. I am not able to reproduce an issue with the code I sent you. The attached video shows how the code works. Furthermore this is standard ASP.NET HttpModule and there is nothing specific to Sitefinity.

    Sincerely yours,
    Ivan Dimitrov
    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
  17. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    29 Jun 2010
    Link to this post
    Hi,

    You were right. The module was not registered at the correct place in the web.config. I'm running the website under IIS 7 and registering the module at the correct place did the trick. It worked !

    Thanks for all the help !

    Saumitra
  18. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    08 Jul 2011
    Link to this post
    Hi Ivan,

    I have set a page as a home page and added the change to web.config, but still unsuccessful with this. PLease let me know how can I achieve this.

    regards,
    Siddesh Kapadi
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Jul 2011
    Link to this post
    Hi Siddesh,

    I am not able to replicate an issue with the code. You can take a look at attached video added several posts above that shows the result.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  20. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    13 Jul 2011
    Link to this post
    Should the handler be implemented, then only the code would work?

    Or are these the only two settngs for this...
  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2011
    Link to this post
    Hello Siddesh,

    If you don't use the handler I don't see how you re going to hook into BeginRequest.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  22. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    13 Jul 2011
    Link to this post
    Oops Ivan Sorry...

    I tink I was not correct asking you my query. here it is again...

    Now, is the handler required to make redirectToHomePage="false" work? This is because I am unable to get only the URL without the page name.

    For example, if I say http://localhost:1234/Myproject
    It appends http://localhost:1234/MyProect/index.aspx

    Here index.aspx is my page name that I have created from the admin and is set as the home page.

    Even after adding, the above attribute in web.config it does not seem to work. I am using sitefinity 3.7 sp4 i.e DLL build version 2136 (Hopefully it is sp4)

    Also, I have a little different requirement. Once the user hits my url i.e http://localhost:1234/myProject/
    the user would see my home page without index.aspx.

    as there are multiple pages nested inside the home page, I want the user to see it as http://localhost:1234/MyProject/innerpage.aspx instead of http://localhost:1234/MyProject/index/innerpage.aspx

    How can I achieve this. Please help.

    Thanks for all your help and looking forward to further assistance.

    Regards,
    Siddesh Kapadi
  23. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    13 Jul 2011
    Link to this post
    For the second task,

    as there are multiple pages nested inside the home page, I want the user to see it ashttp://localhost:1234/MyProject/innerpage.aspx instead ofhttp://localhost:1234/MyProject/index/innerpage.aspx

    you can add additional Urls for each page
    or
    create an Url rewrite module (url rewrite)
  24. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    13 Jul 2011
    Link to this post
    Hi,

    Thanks for your reply..

    Now on the page I have a style sheet. It is also rewritten and later is not found with my , so the page looks broken....

    So, I think this would now be the ideal solution... any input on this and the earlier one from telerik or any other member?

    Regards,
    Siddesh Kapadi

  25. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    13 Jul 2011
    Link to this post
    If the styles are the only problem, you can include them with the absolute path like this:
    /styles/mystyle.css
    and not relative ( ../styles/mystyle.css).

    Same should be applied for the js files.
  26. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    13 Jul 2011
    Link to this post
    Hi,

    The style files are all handled dynamically when using themes... but for js.. we register it using relative paths as they appear on the master page and can have any nested levels of directories..

    if as you say I create a Absolute path.. and I deploy my application as virtual directory I am sure these would not work and only relative would.

    Please correct me if I am wrong.

    Regards,
    Siddesh Kapadi
  27. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    13 Jul 2011
    Link to this post
    You are right, it will not work if you deploy you app to a virtual directory.

    There is another solution though. You can create your own CmsHttpModule an override GetUrl method, like bellow.
    Don't forget to register this one in web.config instead of default one.
    <add name="Cms" type="Telerik.Cms.Web.CmsHttpModule, Telerik.Cms" />
    should be replaced with
    <add name="CmsRewriteModule" type="CmsRewriteModule, App_Code"/>

    Sample:
    public class CmsRewriteModule : CmsHttpModule {

            protected override string GetUrl(System.Web.HttpContext context) {


    if context.Request.Url.RawUrl == "/page.aspx"
    return "/pathtootherpage.aspx";
    }
    }

    You can give it a try.
  28. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    21 Jul 2011
    Link to this post
    Hi,

    When I inherit from the CMSHttpModule and override the method GetUrl() I do not get the page to be displayed and it goes on for forever processing mode.

    If I comment this, then I get the page, but the issue still remains....

    Any help from telerik admins?

    Regards,
    Siddesh Kapadi
Register for webinar
28 posts, 0 answered