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

Forums / General Discussions / URL rewriting

URL rewriting

19 posts, 1 answered
  1. Sharon
    Sharon avatar
    17 posts
    Registered:
    06 Feb 2009
    21 Jul 2009
    Link to this post
    How to mask the folder name in the URL and rewrite with the one I specify.

    Thanks,
    Sharon
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    23 Jul 2009
    Link to this post
    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.
  3. Firesky
    Firesky avatar
    2 posts
    Registered:
    19 Dec 2008
    24 Jul 2009
    Link to this post
    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
  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    24 Jul 2009
    Link to this post
    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.
  5. Sharon
    Sharon avatar
    17 posts
    Registered:
    06 Feb 2009
    24 Jul 2009
    Link to this post
    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



  6. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    28 Jul 2009
    Link to this post
    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.
    Answered
  7. Sharon
    Sharon avatar
    17 posts
    Registered:
    06 Feb 2009
    31 Jul 2009
    Link to this post
    Hi Vlad,

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

    Thanks,
    Sharon
  8. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    22 Jan 2010
    Link to this post
    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!
  9. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    22 Jan 2010
    Link to this post
    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.
  10. vinamra
    vinamra avatar
    45 posts
    Registered:
    23 Oct 2012
    08 Jun 2010
    Link to this post
    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.
  11. roger
    roger avatar
    2 posts
    Registered:
    21 Jun 2010
    21 Jun 2010
    Link to this post
    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> 
  12. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Jun 2010
    Link to this post
    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
  13. roger
    roger avatar
    2 posts
    Registered:
    21 Jun 2010
    24 Jun 2010
    Link to this post
    Exactly. That´s what I want to do.
    How can I do that?
  14. Ideawire
    Ideawire avatar
    2 posts
    Registered:
    27 Jul 2010
    13 Oct 2010
    Link to this post
    Did anyone else have an issue with it breaking the CSS links?
  15. jkregala
    jkregala avatar
    159 posts
    Registered:
    22 Sep 2009
    19 Jan 2011
    Link to this post
    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.
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 Jan 2011
    Link to this post
    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
  17. jkregala
    jkregala avatar
    159 posts
    Registered:
    22 Sep 2009
    20 Jan 2011
    Link to this post
    Ok noted.
  18. Bo Sep
    Bo Sep avatar
    21 posts
    Registered:
    27 May 2010
    23 Feb 2011
    Link to this post
    Hi Sharon,
    Have you ever come across any issues of masking the Sitefinity folder?

    Regards
  19. JAllen
    JAllen avatar
    34 posts
    Registered:
    23 Dec 2010
    28 Mar 2011
    Link to this post
    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,
Register for webinar
19 posts, 1 answered