Change URL format for modules with multiple content types

Use the following procedure to configure the URL format for modules that have more than one content type. For example, Blogs module that has Bogs and Blog posts content types.

Because the Blogs and the Blog posts have different URL format – the URL of the posts includes the URL of the blog, you cannot use the above procedure and change only the parameter of the data provider. To change the format of modules with multiple content types, you must create a custom provider and override some of the methods.

The following procedure removes the name of the blog from the URL of the blog post. After completing the procedure, you can further change the URL format using the advanced settings in the backend. For more information, see Manage the URL format through the advanced settings below.

Perform the following:

1. Implement the custom provider

  1. Create a new class and inherit from Telerik.Sitefinity.Modules.Blogs.Data.OpenAccessBlogProvider
    Because you want to modify the URL format for blogs and posts, you need two properties to hold the format strings.
  2. Override the method that returns the format string, when called by Sitefinity. 
    The method is called GetUrlFormat and accepts an ILocatable item as an argument. The item is an instance of the object whose URL format you must return. 
    Check its type and return a different format for Blog and BlogPost, retrieved from the properties you have created.
  3. Set values to your properties. 
    You do this when the custom provider is initialized by reading the values from the configuration. You also supply defaults, in case the values in the configuration are not set.

Use the following code sample:

2. Register the new provider in Sitefinity

To use the newly created data provider, you must register it. You can do this either by replacing the default provider, or by registering it as a new provider:

  • Replace the default provider
    Sitefinity CMS starts using your custom provider and applies the new URL format for all newly created items.
    1. Click Administration » Settings » Advanced.
    2. In the treeview on the left, click Blogs » Providers » OpenAccessDataProvider.
    3.  In ProviderType, enter the CLR type of your newly created provider.
    4. This is the full namespace and type of the custom class you created.
    5. Save your changes.
  • Create a new provider
    This way, you can items with the new URL format under the new provider. The default provider is still usable and holds all of the previously created items.  
    1. Click Administration » Settings » Advanced.
    2. In the treeview on the left, click Blogs » Providers » Create new.
    3. Specify a Name and a Title for your custom provider.
    4. In ProviderType, enter the full namespace and type of the custom class you previously created.
      For example, enter CustomUrls.CustomBlogsProvider
    5. Save your changes.

NOTE: If you have Sitefinity CMS Multisite you may have more than one provider. In this case, you can choose for which provider to apply the desired behavior, or you can apply it to all by replacing them with the custom one. 

3. Republish all blog posts

Once you register the new provider, all newly created posts have the new URL format - without the name of the blog. To change the URL for previously created posts, you need to republish all posts. You can do this manually or by using the following code sample:

Manage the URL format through the advanced settings

Once you have created and registered your provider, you can manage its parameters through the Advanced settings.

  1. Click Administration » Settings » Advanced.
  2. In the treeview, click Blogs.
    • If you have replaced the default provider, click OpenAccessDataProvider » Parameters.
    • If you have created a new provider, click the custom provider » Parameters.
  3. You can see two parameters - blogUrlFormat and blogPostUrlFormat.
    You can see that after registering the new parameter, the value of blogPostUrlFormat has been changed from /[Parent.UrlName]/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName] to /[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]. Thus, removing the blog's URL from the URL of its blog posts.
  4. Use the parameters to further change the URL format if required.
  5. In order for the changes to take effect, republish all blog posts.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?