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

Forums / Developing with Sitefinity / Need some assitance witht he URL Rewriting feature in SiteFinity

Need some assitance witht he URL Rewriting feature in SiteFinity

5 posts, 0 answered
  1. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    22 Oct 2008
    Link to this post
    Afternoon everyone,

    URL rewriting that SiteFinity provides is a huge feature which we are most interested in taking advantage of when we go live. I have begun playing with it a little and would like a few questions answered if you do not mind.

    So i have the following url:
    /BookTrip/ProcessResortSearch.aspx?srch=Ab8765446eD2754

    That i am rewriting to:
    /Resorts/Ab8765446eD2754

    I am using the following simple rule:
    <rule> 
      <url>Resorts/(.*)</url> 
      <rewrite>/BookTrip/ProcessResortSearch.aspx?srch=$1</rewrite> 
    </rule> 


    This seems to work, but i am not sure how to read the querystring? Is there some special way of doing this? Do i use the normal Request.QueryString["srch"] ? Or do i have to create a class that gets the current URL and extracts everything after the last / to get my querystring value? Or is there some SiteFinity class that will do all of this for me?

    Secondly i found the following post: http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-tabbb.aspx. SelArom asked how to achieve the opposite of the URL rewriting and i am interested in just this... For example...

    If a page is requested (/BookTrip/ProcessResortSearch.aspx?srch=
    Ab8765446eD2754) i would like the URL to physically be rewritten to /Resorts/Ab8765446eD2754... I guess you would not call this "the opposite of url rewriting" but maybe something along the lines of a redirection to the rewrite rule... Does that make sense?

    Any request to ProcessResortSearch.aspx rewrites the url to /Resorts/

    I find it odd that in all the code i have for all my controls i have to to redirects to the rule url rather than a rule being created that states that any page that matches this expression, rewrite the url to xxxxxxx... Maybe it is just me not really undertsand the rewrite concept.

    That is all for now but i am sure this thread will grow as i find more questions on this...

    Thanks,

    Nugs
  2. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    23 Oct 2008
    Link to this post
    Hi Duncan,

    1.  In order to use the query string parameters, just use the normal Request.QueryString.  

    2.  Regarding reverse URL mapping; I don't have an elegant solution.  I suppose you could use "Request.RawUrl" to examine the URL the user is using.  If you don't like it, then you could do a Response.Redirect to the URL you would prefer they use.  This is going to force you to duplicate the URL rewriting, in reverse, you created in the web.config.  Others might have a better suggestion.

    ----

    I'm curious though, provided your web site is using external links in the desired format:

    ~/Resorts/Ab8765446eD2754

    Why would anyone ever decide to randomly type:

    ~/BookTrip/ProcessResortSearch.aspx?srch=Ab8765446eD2754

    I'm trying to understand how anyone would figure out these internal URLs.

    Thanks Duncan.

    Gabe Sumner


  3. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    23 Oct 2008
    Link to this post
    Hey Gabe, good to hear from you.

    This question relates to my earlier post: http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bgmcbb.aspx

    SiteFinity provides the capability to set multiple URL's for a page, it also provides the capability to set any one of these URL's as the default URL... However... When a like is made to a page in one of the SiteFinity modules, it makes the link literal to the location of the page, regardless of what the default URL might be... I can even go into the page properties and set the URL of the page to be /Resorts/

    1) If i chnage the page URL to a new default, this does not change any existing links to the page site wide.

    2) Any new links generate still ignore this default URL anyways.

    So my issue is that i, most likely, will have non-technical users adding these links... They will navigate the sitemap and select a page to link to... It will use the direct mapping to the page and ignore any defaults i might have set... This is why i was thinking of doing exactly what you suggested actually and checking each page requests againast the Rewire/Rules properties of the web.config. I posted a sperate question about this: http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bghdhk.aspx

    Personally i think it would be a great feature to allow the default urls to be used as the default link to the pages (makes sense to me), in addition to this it would be amazing if, when a pages default url is changed, all site links to this page change to meet the new default setup. The latter might be some work but certainly a nice feature. Like i said in the post i mentioned above, i am thinking of writing a "intercept class" that will do this based on the rewrite rules in the web config. What you think?

    Duncan
  4. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    23 Oct 2008
    Link to this post
    Sorry Gabe, not sure if i actually answered your question (still need my second cup of coffee this morning)

    Why would anyone ever decide to randomly type:

    ~/BookTrip/ProcessResortSearch.aspx?srch=Ab8765446eD2754

    I'm trying to understand how anyone would figure out these internal URLs.
    You are correct, external users accessing the  site will most likely access the site with the rewritten URL. But it is the internal links to these pages that will not access the page via the rewritten url or even via the default url i setup for the page...


    In some cases i have very long URL's that are generated based on the page structure... /PageGroup1/PageGroup2/Page/Page/Page.aspx?qry=querystringhere as apposed to /resorts/querystringhere


    So really my question is regarding the internal linking of SiteFinity...


    Duncan
  5. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    23 Oct 2008
    Link to this post
    Hi Duncan,

    Perfect!  I understand now.  Thank you for offering more information about your project.

    Personally i think it would be a great feature to allow the default urls to be used as the default link to the pages (makes sense to me), in addition to this it would be amazing if, when a pages default url is changed, all site links to this page change to meet the new default setup. 

    I think we agree on this.  Georgi wrote in your other thread that LinkManager does not currently consider additional or preferred URLs.  This feels like a problem to me.  

    To your other point (about retroactively correcting all web site links if the URL is changed); this might be tricky.  One thought I have is that LinkManager ceases to use URL's and begins to base the link on the Guid of the page.  

    Prior to the page being rendered to the browser, this Guid would be converted to the page's default URL.  This would allow you to make massive changes to the URL's and web site structure without any negative impact to the underlying web links.

    The Sitefinity team would know better than I the performance and technical impacts of this approach though...

    An intercept class might be your only option for now.  Perhaps other have a better suggestion?

    Certainly let us know if you manage to solve this!

    Gabe Sumner







Register for webinar
5 posts, 0 answered