Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): General Discussions > URL rewriting

URL rewriting

  • Sharon avatar

    Posted on Jul 20, 2009 (permalink)

    How to mask the folder name in the URL and rewrite with the one I specify.

    Thanks,
    Sharon

    Reply

  • Vlad Vlad admin's avatar

    Posted on Jul 23, 2009 (permalink)

    Hi Sharon,

    You can use the Sitefinity Advanced URL Rewriter, described in the User Manual.
    For example, you can create a rule like this:

        <urlrewrites ignoreCase="true"
          <rule> 
            <url>/VisibleFolder/(.*)</url> 
            <rewrite>/MaskedFolder/$1</rewrite> 
          </rule> 
        </urlrewrites> 

    And the request to:

    http://domain/VisibleFolder/page1.aspx

    will actually open the page with the following URL:

    http://domain/MaskedFolder/page1.aspx


    Please let me know if you mean something different.

    Sincerely yours,
    Vlad
    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.

    Reply

  • Firesky avatar

    Posted on Jul 24, 2009 (permalink)

    Hi,

    You have created the rule for exactly what I meant, but it is not working. I am using IIS7 is there anything else that I have to change. I have URL Rewrite already installed in my server. Please provide me with detailed instruction.

    Thanks,
    Sharon

    Reply

  • Vlad Vlad admin's avatar

    Posted on Jul 24, 2009 (permalink)

    Hello Sharon,

    Could you please elaborate more about the task you want to accomplish?

    Regarding the rule example in my previous post, you should have the following CMS pages:

    [Site Map]
          MaskedFolder
                page1

    Do you have a similar pages structure?

    Also you said:
    "I have URL Rewrite already installed in my server."

    What kind of URL Rewrite do you mean?


    All the best,
    Vlad
    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.

    Reply

  • Sharon avatar

    Posted on Jul 24, 2009 (permalink)

    Hi Vlad ,

    The URL format that I require is:
    URL: http://mydomain.com/oldfolder/index.aspx rewritten to:
    Rewrite URL: http://mydomain.com/newfolder/index.aspx

    I am using Windows Server 2008 installed in my server with IIS 7. The URL Rewrite feature for IIS 7 is installed in the server by the hosting company.

    Hope this information is helpful for you to provide the necessary instructions.

    Also, is there any way where I can mask the "Sitefinity" in the URL.

    Thanks,
    Sharon



    Reply

  • Answer Vlad Vlad admin's avatar

    Posted on Jul 28, 2009 (permalink)

    Hi Sharon,

    As I understand, you are using the URL Rewrite Module for IIS7.

    In this case, we found out that you can use a rule like the following. For instance, it masks the sitefinity folder with mycms:
      <system.webServer> 
        ... 
        <rewrite> 
            <rules> 
                <rule name="Mask Sitefinity"
                    <match url="^mycms/(.*)$" /> 
                    <action type="Rewrite" url="sitefinity/{R:1}" /> 
                </rule> 
            </rules> 
        </rewrite> 
      </system.webServer> 

    However, changing the Sitefinity folder globally is not considered in the current version of Sitefinity. I mean, that you won't be able to change all the links in the administration from /Sitefinity/ to /MyCms/.

    Actually, you can use another work around if it is appropriate for you.
    You can create another rule, which first redirect the URL from /Sitefinity/ to /MyCms/, i.e:
      <system.webServer> 
        ... 
        <rewrite> 
          <rules> 
            <rule name="Mask Sitefinity 1" stopProcessing="true"
              <match url="^sitefinity/(.*)$" /> 
              <action type="Redirect" url="mycms/{R:1}" /> 
                <conditions> 
                    <add input="{REQUEST_FILENAME}" negate="true" pattern="^(.*)\.asmx" /> 
                </conditions> 
            </rule> 
            <rule name="Mask Sitefinity 2"
              <match url="^mycms/(.*)$" /> 
              <action type="Rewrite" url="sitefinity/{R:1}" /> 
            </rule> 
          </rules> 
        </rewrite> 
      </system.webServer> 

    But this is not all. When you do a post back request, it will be redirected and the post back information will be lost, because the action attribute in the HTML Form is still pointing to the Sitefinity folder. So you have to replace the action attribute as well. You can do this by implementing a custom form adapter. For example create a file (CustomFormAdapter.cs) with the following code in the ~/App_Code folder:
    using System; 
    using System.Collections.Generic; 
    using System.Web; 
    using Telerik.Cms.Web; 
    using System.Web.UI; 
    using System.IO; 
     
    namespace Sitefinity.Custom 
        public interface IAdminPage 
        { } 
     
        public class CustomFormAdapter : FormAdapter 
        { 
            static CustomFormAdapter() 
            { 
                adminFolderUrl = UrlHelper.SitefinityRoot.Replace( 
                    Telerik.Cms.Configuration.ConfigHelper.Handler.SitefinityRoot.ToLower(), 
                    "mycms"); 
            } 
     
            internal static string adminFolderUrl; 
     
            protected override void Render(HtmlTextWriter writer) 
            { 
                AdminPage adminPage = this.Page as AdminPage; 
                if (this.Page is AdminPage != null 
                    || this.Page is IAdminPage) 
                    base.Render(new CustomFormHtmlTextWriter(writer)); 
                else 
                    base.Render(writer); 
            } 
     
            public class CustomFormHtmlTextWriter : HtmlTextWriter 
            { 
                public CustomFormHtmlTextWriter(TextWriter writer) 
                    : base(writer, null
                { 
                    base.InnerWriter = writer; 
                } 
     
                public CustomFormHtmlTextWriter(HtmlTextWriter writer) 
                    : base(writer, null
                { 
                    base.InnerWriter = writer.InnerWriter; 
                } 
     
                public override void WriteAttribute(string name, string value, bool fEncode) 
                { 
                    if (name == "action"
                    { 
                        value = value.Replace(UrlHelper.SitefinityRoot, CustomFormAdapter.adminFolderUrl); 
                    } 
                    base.WriteAttribute(name, value, fEncode); 
                } 
            } 
        } 

    And declare it in the ~/App_Browsers/BrowserFile.browser:
    <browsers> 
      <browser refID="Default"
        <controlAdapters> 
          <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="Sitefinity.Custom.CustomFormAdapter, App_Code" /> 
        ... 
     

    Also, because the Login.aspx does not inherit Telerik.Cms.Web.AdminPage class, you should mark it with Sitefinity.Custom.IAdminPage interface, which is implemented in CustomFormAdapter.cs and has mo members. In the ~/Sitefinity/Login.aspx.cs add the interface:
     
    public partial class Admin_Login : System.Web.UI.Page, Sitefinity.Custom.IAdminPage 


    I hope this is helpful.
    Do let us know if you have additional questions.

    Sincerely yours,
    Vlad
    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.

    Reply

  • Sharon avatar

    Posted on Jul 31, 2009 (permalink)

    Hi Vlad,

    Thanks a lot. Your code helped me a lot and it works!!!!

    Thanks,
    Sharon

    Reply

  • bemara57 Master avatar

    Posted on Jan 21, 2010 (permalink)

    Excellent info!

    What would be the implications of rewriting folder paths to pages. For example, rewriting http://example.com/page1 to http://example.com/page.aspx?

    By the way, is all this still relevant to 3.7?

    Thanks!

    Reply

  • Georgi Georgi admin's avatar

    Posted on Jan 22, 2010 (permalink)

    Hello bemara57,

    This is relevant to 3.7 as well. 

    Rewriting directories to pages is possible. Try with this rule:

    <rule>
       <url>/page1</url>
       <rewrite>/page.aspx</rewrite>
    </rule>

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

    Reply

  • Posted on Jun 8, 2010 (permalink)

    hi

    how to rewite the http://site/sitefinity  to http://site/admin  by using the Sitefinity Advanced URL Rewriter.

    the above mention code and settings are of URL Rewrite Module for IIS7. how to achieve this with Sitefinity Advanced URL Rewriter


    thanks.

    Reply

  • roger avatar

    Posted on Jun 21, 2010 (permalink)

    How can I do this bellow with Apache mod_rewrite .htaccess ?

    <system.webServer> 
        ... 
        <rewrite> 
          <rules> 
            <rule name="Mask Sitefinity 1" stopProcessing="true"
              <match url="^sitefinity/(.*)$" /> 
              <action type="Redirect" url="mycms/{R:1}" /> 
                <conditions> 
                    <add input="{REQUEST_FILENAME}" negate="true" pattern="^(.*)\.asmx" /> 
                </conditions> 
            </rule> 
            <rule name="Mask Sitefinity 2"
              <match url="^mycms/(.*)$" /> 
              <action type="Rewrite" url="sitefinity/{R:1}" /> 
            </rule> 
          </rules> 
        </rewrite> 
      </system.webServer> 

    Reply

  • Georgi Georgi admin's avatar

    Posted on Jun 24, 2010 (permalink)

    Hello roger,

    Could you please clarify your question? You want to translate this to the apache mod rewrite syntax?

    Regards,
    Georgi
    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

    Reply

  • roger avatar

    Posted on Jun 24, 2010 (permalink)

    Exactly. That´s what I want to do.
    How can I do that?

    Reply

  • Posted on Oct 13, 2010 (permalink)

    Did anyone else have an issue with it breaking the CSS links?

    Reply

  • jkregala Intermediate avatar

    Posted on Jan 19, 2011 (permalink)

    Hello guys for example I want to apply this with my entire /Sitefinity/ sub-directory in order to hide the Admin panel from all public users what would be the approach with the code? For example I would be redirecting all pages inside the /Sitefinity/ directory into a dummy page.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jan 19, 2011 (permalink)

    Hello jkregala,

    You cannot hide the Sitefinity folder. You can make only redirects as Vlad's post from 7/28/2009 shows this. Basically this hides /Sitefinity/ when you are trying to access the backend. Actually the entire backend relies on files under "Sitefinity" folder. Furthermore we use WebService to bind the content grids and using rewriting or redirecting could break the response from the service.

    Kind 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

    Reply

  • jkregala Intermediate avatar

    Posted on Jan 19, 2011 (permalink)

    Ok noted.

    Reply

  • Bo Sep avatar

    Posted on Feb 23, 2011 (permalink)

    Hi Sharon,
    Have you ever come across any issues of masking the Sitefinity folder?

    Regards

    Reply

  • JAllen avatar

    Posted on Mar 28, 2011 (permalink)

    Hi Vlad/Ivan,
    The solution outlined here works great until you introduce languages/cultures and then we start getting issues.  We want to use the PathPrefix method for languages, so this moves the login page to ~/en/mycms/login.aspx where it breaks.

    If we leave it as 'sitefinity' in the url, it works with cultures.  If we turn off cultures by setting persistenceMode="None", it works with the rewriting to 'mycms'.

    Can you help me figure out how to get both working together?

    Thanks,

    Reply

  • Register for webinar
Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): General Discussions > URL rewriting