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

Forums / Sitefinity SDK / Product Module - How to change Url?

Product Module - How to change Url?

8 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    28 Jan 2011
    Link to this post
    Hi there,

    I've got my product module working and was able to get to he point of dropping a front end Listview control on the page. Clicking the product takes me to a detail view which brings me to my next question. The url that is generated has the date in the url, as if it was a news item or a blog post. This makes no sense for so many reasons. Can someone point me to the chunk of code that defines this and perhaps provide some suggestions on how this could be changed? Ideally I'd like to have a url that includes the category defined for the product or maybe a custom field that I allow the user to define.

    So instead of a url like this:
    http://sitename.com/productspage/2011/01/28/product-name

    I want to have:
    http://sitename.com/productspage/category/brand(customattrib)/product-name
    ie
    http://sitename.com/productspage/trucks/ford/f150-used-low-milage

    Thanks in advance for any help.
    Regards,
    Phill
  2. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    01 Nov 2016
    02 Feb 2011
    Link to this post
    Hello Phill Hodgkinson,
    Hi Phill, you're completely right about this making no sense. And we should have provided a more practical sample of urls in the Products module. There are several ways to achive what you need here:

    1) The fast way to do is by overriding the CompileItemUrl<T> of the povider and return your custom build url.
    2) Override GetUrlFormat(ILocatable item)
    This returns a url formatting expression - the default one is actually "/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]" and that is what you got in the Products Module.
    So basically, you can make your own formatting expressions based on the public properties of the ProductItem class.

    3) The formatting expression can be configured from the Provider configuration settings, by going into the backaned UI -> Advanced settings =>  ~/Sitefinity/Administration/Settings/Advanced, opening the Products configuration -> Providers - >OpenAccessProvider - > Parameters and adding a parameter with name urlFormat and with the value of your expression. This way you can change the url building also of the existing modules like News, Events etc. Important: currently you need to restart the applicaiton in order this to take effect , since we cache these settings - we will address this problem in a recent build.

    If you have a property in your expression that cannot be directly taken from the Public Properties of the prodduct item - like UrlName and PublishedDate,as the case with [category]. You can still use expression like "/CategoryName/UrlName". But you need to override protected virtual string GetUrlPart<T> - here you can make custom parsing of properties in the expression which cannot be resolved automatically.

    For example the method body can be
    if(key=="CategoryName") return GetCategoryNameForItem(item)
    else
    return base.GetUrlPart ....



    All the best,
    Nikolay Datchev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. khaja
    khaja avatar
    1 posts
    Registered:
    04 Mar 2011
    04 Mar 2011
    Link to this post
    I have the similar problem.
    i have a web address as http://www.xyz.com.
    when i register the site example registered as moin

    then it need to be change as http://www.moin.xyz.com

    plz replay me as sson as possible.

    thnks & regds

    moin
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Mar 2011
    Link to this post
    Hi,

    Sitefinity uses relative and dynamic urls. You want to change the host, which actually is relative to the urls we use. Once you create a subdomain for your domain, you should change the project location. You need to move the project in the root of your subdomain.

    Best wishes,
    Ivan Dimitrov
    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. Greg
    Greg avatar
    82 posts
    Registered:
    08 Aug 2012
    03 Jun 2011
    Link to this post
    So I followed #3 above, restarted the site, resaved all content items which worked great. In my urlFormat parameter, I set /[Title] to be the url. However, if my products items have spaces in the name, the space gets included in the url as opposed to a dash. Is there any way to modify this or am I going to have to rename all of my products items?

    Thanks,
    Greg
  6. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    06 Jun 2011
    Link to this post
    @Phil: did you managed to get this working? I'm also trying to get some nice url's based on filtering.

    I want to have the following scenario:

    - Category list on the left of the page
    - Company list on the right of the page
    - Click on a category and filter the list of companies.
    - The URL should then be: http://www.mycompany.com/companies/category/

    Any suggestions?

    Thanks,
    Daniel
  7. Sonu Kapoor
    Sonu Kapoor avatar
    41 posts
    Registered:
    24 Apr 2006
    12 Jul 2011
    Link to this post
    Phil, Were you able to figure this out? I would like to do the same, but I cant figure out how to use the GetCategoryNameForItem method to return the category name. Can you post your code?
  8. Sonu Kapoor
    Sonu Kapoor avatar
    41 posts
    Registered:
    24 Apr 2006
    14 Jul 2011
    Link to this post
    If anybody still interested, here is the solution:

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/how-to-use-a-custom-url-in-the-products-module---solution.aspx
8 posts, 0 answered