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

URL Rewriting

13 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    17 Feb 2011
    Link to this post
    I've read a couple of threads on Sitefinity and URL rewriting and everyone seems to refer to the documentation where you can read about it. The online documentation only seems to highlight the available class for this purpose, but I don't see any kind of description for it.

    I'm currently trying to watch a webinar on the topic, but it is deadly slow - is there somewhere where we can rather download that webinar?

    In some of the threads it looks like people are using the rewriting technique to be more of a redirect. My questions: We're creating a site where you will have something like http://domain.com/products/electrical/toaster. Take note we're also using extensionless urls. But, we also want that URL to be rewritten as http://domain.com/products/product?productName=toaster, or somewhere along that line.

    Questions:
    1. I noticed someone talking about this being a redirect. Doesn't that negatively impact a search engine. Rather doesn't that mean that the search engine is going to see the 301 redirect and index the wrong URL (http://domain.com/products/product?productName=toaster)
    2. Where can we get the full documentation for this subject?

    Thanks,
    Jacques
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    21 Feb 2011
    Link to this post
    Hello Jacques,

    Do you refer to this online documentation? - http://www.sitefinity.com/documents/UserManual_3_7.pdf
    The URL Rewriting topic is documented on page 195 in this guide. We do not have the webinar as a downloadable resource though.

    The rewriting by default is working as rewriting - no redirect. This means that the user receives 200/OK status, rather than 301.

    Kind regards,
    Georgi
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    22 Feb 2011
    Link to this post
    Yes thanks Georgi, that's what I was looking for.  <url>
    I'm using URL rewriting in conjunction with extensionless URLs and trying the following url match with rewriting:          
    <rule>
        <url><![CDATA[(?<=\/property-for-sale\/)(.+)]]></url>
        <rewrite>property-search-results.aspx?location=$1</rewrite>
    </rule>

    with the url:
    http://www.companyname.com/property-for-sale/surrey/london/united-kingdom

    The intended rewrite should result in the URL:
    http://www.companyname.com/property-for-sale/property-search-results?location=/surrey/london/united-kingdom

    It does in fact redirect to this URL, but if we run in debug mode and put a break point in the Page_Load event of the property-search-results page it hits that break point repeatedly and the resulting page looks damaged.

    What would cause the repeated page load event?
    In the <rule> that is created, or rather then the rule is executed it will transfer processing to the 'property-search-results' page, does that rule get executed again after the transfer?


  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Feb 2011
    Link to this post
    Hello J.Hoventer,

    The problem is that when you remove the .aspx extension the rule starts matching requests to .css, .js, .axd and other resources which are needed for your pages to function properly. This means that you have two write a rule which matches all strings not containing those extensions. The bellow rule will match all urls except the ones containing any of the highlighted extensions:

    ^(?=.*?\b([\w-]+)-([\w-]+)\b)((?!\.(jpg|jpeg|gif|png|bmp|tiff|tga|svg|css|js|rss|ashx)).)*$

    The rule matches urls in the pattern: /page-name/

    For the sake of simplicity I was testing with \. which matches all URLs not containing "." character:

    <rule>
      <!-- Client requests /firstname-lastname -->
      <url>^(?=.*?\b([\w-]+)-([\w-]+)\b)((?!\.).)*$</url>
      <!-- However is shown as /page.aspx?Param1=firstname&Param2=lastname without changing url in the browser's url bar -->
      <rewrite>/UrlRewrites/home?dcfname$1&dclname=$2</rewrite>
    </rule>

    You can use this on-line tool for testing your regular expressions.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    17 Mar 2011
    Link to this post
    Hi Radoslav,

    Thanks for the answer, we'll be implementing that tomorrow.

    I've noticed another problem with Sitefinity's Menu object. When you're on a page that makes use of URL Rewriting the menus point to the wrong place. On any other page the menus work, but on rewritten pages they fail.

    What do I need to change to get this working? I didn't see anything about it in the documentation.

    Regards,
    Jacques
  6. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    18 Mar 2011
    Link to this post
    Hi Radoslav

    In your response you said I should use:
    ^(?=.*?\b([\w-]+)-([\w-]+)\b)((?!\.(jpg|jpeg|gif|png|bmp|tiff|tga|svg|css|js|rss|ashx)).)*$

    and then a few lines later you used the example:

    <rule>
      <!-- Client requests /firstname-lastname -->
      <url>^(?=.*?\b([\w-]+)-([\w-]+)\b)((?!\.).)*$</url>
      <!-- However is shown as /page.aspx?Param1=firstname&Param2=lastname without changing url in the browser's url bar -->
      <rewrite>/UrlRewrites/home?dcfname$1&dclname=$2</rewrite>
    </rule>

    Are you intending for us to add the first string as a rule above the others and then add the second rule to deal with the real URLs we're looking for. I've tested this int he online tool you mentioned (with my URL) and it does nothing.

  7. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    22 Mar 2011
    Link to this post
    Hi J.Hoventer,

    Please note the previous reply says "for the sake of simplicity". Generally if if I use (?=.*?\b([\w-]+)-([\w-]+)\b)((?!\.).)*$ then it will catch all urls containing "." in their pattern. As the other case you have to list all extensions which should not be rewritten on your site.

    Best wishes,
    Radoslav Georgiev
    the Telerik team
  8. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    22 Mar 2011
    Link to this post
    This URL Rewriting functionality is causing problems with the RadMenu href values. I've posted about it, but no-one is responding:

    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/bugs-issues/url-rewriting-and-sitefinity-menu-bug.aspx

  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    22 Mar 2011
    Link to this post
    Hi J.Hoventer,

    Sitefinity UrlRewriting does not rewrite outbound links. This is the reason for the behavior you are experiencing. If you wish to have outbound rewrites you need to utilize the IIS Urlrewriter. If you want to use this rewriter. You have to create a class which will override the default Sitefinity CmsHttpModule. You need to override one method and set your site to use this particular class instead of the default one:

    using System.Web;

    using Telerik.Cms.Web;

     

    /// <summary>

    /// Summary description for CustomCmsHttpModule

    /// </summary>

    public class CustomCmsHttpModule: CmsHttpModule

    {

        protected virtual CmsRequest GetCmsRequest(HttpContext context)

        {

            return new CmsRequest(context.Server.UrlDecode(context.Request.Url.PathAndQuery));

        }

    }




    Greetings,
    Radoslav Georgiev
    the Telerik team
  10. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    24 Mar 2011
    Link to this post
    Hi Radoslav,

    By the following section of your response:

    Sitefinity UrlRewriting does not rewrite outbound links. This is the reason for the behavior you are experiencing. If you wish to have outbound rewrites you need to utilize the IIS Urlrewriter.

    Are you saying that we should rather not use the Sitefinity URL rewriter, but instead use the IIS rewriter, or are you saying that these two rewriters need to be used together?

    In your code sample your object is inheriting from CmsHttpModule, it would seem then that you're removing your rewriter entirely. Is that correct?

    Jacques
  11. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Mar 2011
    Link to this post
    Hello J.Hoventer,

    Your observations are correct. If you need to rewrite outbound links you should use the IIS rewriter. This rewriter is better used separately, not in combination with our rewriter.

    Greetings,
    Radoslav Georgiev
    the Telerik team
  12. JAllen
    JAllen avatar
    34 posts
    Registered:
    23 Dec 2010
    04 Aug 2011
    Link to this post
    Hi Radoslav/Telerik,

    I'm in a similar situation where I think I need to use OutboundRules, but the quote below scares me a little:

    "If you need to rewrite outbound links you should use the IIS rewriter. This rewriter is better used separately, not in combination with our rewriter." (Radoslav)

    Does this mean that to be able to use the IIS rewriter to achieve OutboundRules, we have forego all of the SF rewriting?!  Eg, will all the rewriting for news articles, CMS pages, etc all stop working as well?  Or would that only apply to my own rewrite rules found in the telerik > urlrewrites section of the web.config?

    For context, our code generates the url with query string parameters and the SF rewrites below do work for external links (ie, typing in ~/product/123/456/abc), but doesn't help us rewrite the links outbound so URLs appear friendly when accessed via internal links.

    <telerik>
      ...
      <urlrewrites>
        <!-- Add your rule elements here -->
        <rule>
          <url>/product/(.*)/(.*)/(.*)</url>
          <rewrite>/product?id=$1&code=$2&manu=$3</rewrite>
        </rule>
        <rule>
          <url>/products/(.*)</url>
          <rewrite>/products?mode=$1</rewrite>
        </rule>
      </urlrewrites>
    </telerik>


    So essentially, if we follow your suggestion, will it have any affects on the rest of the rewriting throughout SF or will it just affect the above rewrites?

    Thanks,
  13. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Aug 2011
    Link to this post
    Hi Jallen,

    The default Url rewirtes will work. The problem comes from conflicting rewrite rules under telerik->urlrewrites
    and the IIS UrlRewirter module. The thing is that if the IIS module has rules that overlap with the ones defined under the Sitefinity UrlRewriteModule the requests might not be served. Otherwise the built in rewriting functionality for main modules remains working.

    Best wishes,
    Radoslav Georgiev
    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
Register for webinar
13 posts, 0 answered