change URL's?

Posted by Community Admin on 03-Aug-2018 16:18

change URL's?

All Replies

Posted by Community Admin on 23-Feb-2011 00:00

I created a usercontrol to show my news items, (the current news widget won't work within my display). I'm able to pull out the news title and the urlname, however the urlname is just the title of my news item. How can I get the correct URL for my news item like the out of the box news widget has?

here is what I'm referring to:
if I enter in a news item in the backend and title it: The following items are being discontinued, the url for that item shows up as /2011/02/23/the-following-items-are-being-discontinued

if I show that same news item in my user controls, the url is:
/the-following-items-are-being-discontinued

and when I click on it nothing happens, where when I click on the URL in the news widget, I can see my news.

how can I get the correct URL for each news item within my user control?
here is that code that i used for the news:

 

var news = from n in App.WorkWith().NewsItems()
                      where n.Status == ContentLifecycleStatus.Live
                      orderby n.Title
                      select n;

 



I then bind it to my datalist and show [title] and [urlname], what should I be using for the URL?

Posted by Community Admin on 24-Feb-2011 00:00

Hello CsharpGuy,

Thank you for contacting Telerik Support.

You can get the default url by subscribing to the DataList control's ItemDataBound event. Consider the sample bellow:

void  dt_ItemDataBound(object sender, DataListItemEventArgs e)
   
       if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
       
           NewsItem itemBound = (NewsItem)e.Item.DataItem;
           string url = itemBound.Urls.Where(u=> u.RedirectToDefault == false).FirstOrDefault().Url;
           //this will give you /2011/02/23/the-following-items-are-being-discontinued
           //then you need to construct a link to your page which contains news control and append the url to this link
       
   
Please pay attention to the last comment - the string url will refer to the default URL of the news item, but you need to reference the link to your page containing the news control, in order to make the news visible when accessed from your custom control.

I hope this information helps. Please let me know if I can assist you any further with this service request. Thank you in advance.

Greetings,
Boyan Barnev
the Telerik team

Posted by Community Admin on 24-Feb-2011 00:00

wow, never would have figured that out. You guys should build a code library or something and have real world working examples like this. So far the v4 documentation isn't that great and has nothing like this in it.


Is something like this possible to pull out all of my pages?

Posted by Community Admin on 25-Feb-2011 00:00

Hi CsharpGuy,

We started working on the documentation articles, so the manual is going to be updated very soon with new samples and How tos. As for the pages, there is implementation for additional urls for pages that can be set from the UI, so you can specify completely differentiate url to resolve the same page with no coding. The feature will be included in the Q1 release.

Best wishes,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 30-Mar-2011 00:00

That codes works for me. I also used myNewsItem.Urls[0].Url and that returns the right Url. 
However, 
how can I control the URL path. mainly I don't want dates in the URL (in general I need to flexibly do the paths ) 
example: 
I want to change "/2011/03/29/how-to-write-code"  to --> "/code/how-to-write-code"

Any tips, hints.

Thanks 

Posted by Community Admin on 30-Mar-2011 00:00

Hello Taha,

There is an option to change the url format of the content modules go to Administration >> Settings >> Advances and expand the News node. Then add urlFormat parameter to the provider. For Key enter "urlFormat". For value enter "/[UrlName]". All without the quotes.

Kind regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 30-Mar-2011 00:00

Can we change the urlFormat for blogs as well?  I tried adding the urlFormat key for the blog provider and it did not update my blog URL's when using a blog posts control.

Posted by Community Admin on 30-Mar-2011 00:00

@Dave, I'm pretty sure you need to a) restart your web app (aka edit the web.config) and b) it will only be applied to new blogs going forward. I did this same change to the Libraries as I didn't think the date in the url to an image made any sense. It would only work for new albums, so I basically had to delete all my images and albums and start from scratch. Hope that helps.

Phill

Posted by Community Admin on 03-Apr-2011 00:00

Hello Ivan,

I have the same issue of Dave, I changed the urlFormat for the blogs and I created new posts but still the url of the new blog posts have the format "date/urlName"

Did I miss anything?

Thanks.

Posted by Community Admin on 04-Apr-2011 00:00

Hello AmrElsayed,

After saving the changes to urlFormat, did you restart the application? You need to do this, because we are not restarting it automatically on adding the key for urlFormat.  Please try modifying the web.config (just press space couple of times and then save) and then make a new blog post and inform me if the issue still persists.

Greetings,
Boyan Barnev
the Telerik team


Posted by Community Admin on 04-Apr-2011 00:00

Helo Boyan,

yes, I added the "urlFormat" parameter, then I restarted the application (and I tried to make any changes in the web.config), then I created a new post in a blog.
the url of the new post is still in the format "date/urlName".

I am using version 4.0.1210.0

Thanks.


Posted by Community Admin on 04-Apr-2011 00:00

I've mentioned already that I had this issue with Libraries and Albums. The key was that after changing the URL format I had to delete the album and start from scratch. I would assume this is the same as Blogs, you can just create a new blog post you need to delete the blog and create a new one, then create a blog post and see if it works. Have you done that?

Cheers,
Phill

Posted by Community Admin on 04-Apr-2011 00:00

Hello AmrElsayed,

Indeed there is a registered  bug concerning this behavior, which is for blogs only. Generally the url should be changed without deleting the old data. The bug ID is #109623 and we'll be working on fixing it. I apologize for the inconvenience caused.

All the best,
Boyan Barnev
the Telerik team


Posted by Community Admin on 04-Apr-2011 00:00

Hello AmrElsayed,

Indeed there is a registered  bug concerning this behavior, which is for blogs only. The bug ID is #109623 and we'll be working on fixing it. I apologize for the inconvenience caused.

All the best,
Ivan Dimitrov
the Telerik team


Posted by Community Admin on 04-Apr-2011 00:00

Hello,

So, Is there any solution that I can do for now (till the bug is fixed) to change the blog post's url format to "urlName" only (without the date portion)?

Another question please, is this bug is scheduled to be released with the next official release of Q1 in April 13th?

Thanks.

Posted by Community Admin on 05-Apr-2011 00:00

Hi AmrElsayed,

I've checked the bug status but we are currently working on bugs with higher status, so I cannot guarantee you if this will be included in the Q1 release or in one of the later internal releases.
Inspecting this issue further it seems that the setting does not apply, because the value for urlFormat is hard coded in the source code. What you can do for now is to create a custom provider for blogs and inheriting from

OpenAccessBlogProvider and override the GetUrlFormat method, specifying the desired urlFormat. Please find below the original implementation from the source:
/// <summary>
 
/// Gets the url format for the specified data item that implements <see cref="ILocatable"/> interface.
 
/// </summary>
 
/// <param name="item">The locatable item for which the url format should be returned.</param>
 
/// <returns>
 
/// Regular expression used to format the url.
 
/// </returns>
 
public override string GetUrlFormat(ILocatable item)
 
 
if (item.GetType() == typeof(Blog))
 
return "/[UrlName]";
 
else if (item.GetType() == typeof(BlogPost))
 
return "/[Parent.UrlName]/[PublicationDate, 0:yyyy'/'MM'/'dd]/[UrlName]";
 
else
 
return base.GetUrlFormat(item);
 

You can change the
return "/[Parent.UrlName]/[PublicationDate, 0:yyyy'/'MM'/'dd]/[UrlName]";
line to
return "/[Parent.UrlName]/[UrlName]";
to achieve the desired functionality, just note that this might result in errors related to items having the same URL, if you have blog posts with the same title and parent.


All the best,
Boyan Barnev
the Telerik team

Posted by Community Admin on 06-Apr-2011 00:00

Hello Boyan,

I created the custom provider.
Then I changed the "ProviderType" of the blogs from "Sitefinity>Administration>Settings>Advanced>Blogs>Providers>OpenAccessDataProvider" to the fully qualified name of my custom provider.

I restarted the application but there are no changes, did I miss anything?

Thanks.

Posted by Community Admin on 07-Apr-2011 00:00

Hi AmrElsayed,

Did you test this functionality by creating a new blog post? The URLs of the already existing blog posts will not be changed unless they are opened for edit and then saved, so that their URLs can be recompiled. Please try creating a new blog post and inform me if the problems still persist.

Regards,
Boyan Barnev
the Telerik team


Posted by Community Admin on 07-Apr-2011 00:00

Thanks a lot Boyan.
It works well.

Posted by Community Admin on 18-Aug-2011 00:00

Hi,

I m using one user control for news listing, all seems to working fine except the news URL.

If the news title contains .(Dot) at the end, then it shows me 404 page not found error.
I can remove the dot from the ending, but Can you please tell me this the single character i need to remove or is there other character also.

But when using default sitefinity news public control it redirects the page to listing page.

Thanks
Asit

Posted by Community Admin on 18-Aug-2011 00:00

Hello Asit Pani,

The problem might be due to the customized urlFormat, the dot (.) character does not get caught by the regular expression we apply when generating URLs on content items creation, so it will be constructed with a dot inside, which results in invalid URL. However I have tested the reported behavior on a new project created with our latest officially supported version - Sitefinity 4.2 and applied a urlFormat of /test/[Title] and created a news arcticle with title "Title." Using the custom URL formatiing, the URL of the article was: localhost:60876/.../Test which excluded the special character, and no 404 was returned.

Greetings,
Boyan Barnev
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

Posted by Community Admin on 05-Sep-2011 00:00

Hey everyone,

I worked through this challenge this past weekend for a personal project.

I have a blog called "Topics" in Sitefinity, and I wanted the URL's for this blog to look like this:

mywebsite.com/.../this-is-my-blog-post

By default Sitefinity creates URL's that look like this:

mywebsite.com/.../this-is-my-blog-post

As described above, the urlFormat property is not applicable to blog posts; even if it were applicable it wouldn't be possible to have different URL formats for different blogs.  (I have others blogs that I want to use the traditional URL format.)

--

My solution was to replace Sitefinity's default OpenAccessBlogProvider with the following custom blog provider:

using Telerik.Sitefinity.Modules.Blogs.Data;
using Telerik.Sitefinity.Blogs.Model;
 
namespace SitefinityWebApp.Extensions.Providers
    public class BlogProvider : OpenAccessBlogProvider
    
        public override string GetUrlFormat(Telerik.Sitefinity.GenericContent.Model.ILocatable item)
        
            if (item.GetType() == typeof(Blog))
            
                return "/[UrlName]";
            
 
            if (item.GetType() == typeof(BlogPost))
            
                // If this is the "Topics" blog then eliminate all parameters from the URL.
                // Example:  http://mywebsite.com/topics/workflow
                var blogItem = (BlogPost)item;
                if (blogItem.Parent.UrlName == "topics")
                
                    return "/[UrlName]";
                
 
                return "/[Parent.UrlName]/[PublicationDate, 0:yyyy'/'MM'/'dd]/[UrlName]";
            
            return base.GetUrlFormat(item);
        
    

I've not done extensive testing on this, but it seems to be working as expected.  The existing blog posts seem to work fine and Sitefinity's widgets also work fine with this custom blogs provider.

As others noted, the URL's for old blog posts do not automatically get updated.  To update the URL's you can manually click through each blog post and re-save it.  Or you can run this code (use at your own risk!!!) in a small ASPX page:

using System;
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Blogs.Model;
 
namespace SitefinityWebApp.Extensions
    public partial class test : System.Web.UI.Page
    
        protected void Page_Load(object sender, EventArgs e)
        
            var manager = BlogsManager.GetManager();
            foreach (var post in App.WorkWith().BlogPosts().Get().ToList())
            
                Response.Write(post.Title + "<br />");
                var editPost = manager.GetBlogPost(post.Id);
                manager.RecompileItemUrls<BlogPost>(editPost);
                manager.Lifecycle.Publish(manager.Lifecycle.GetMaster(editPost));
                manager.SaveChanges();
            
        
    

That's it.  This is my own personal project and testing, so please be careful with this code.  When in doubt, make a backup.   :)

Gabe
================

Posted by Community Admin on 09-Jun-2015 00:00

Hi all,
I followed the steps. The thing is when we preview the draft or unpublished blog it throws a 404.
The Sitefinity URL query rules for preview no longer show. Is there a fix for this?

Posted by Community Admin on 07-Jun-2017 00:00

Has anyone run into the issue where after applying the new url format and you try clicking on the blog in the backend and it gives you a space in the url that then gives you a resource not found page

ie:
www.mysite.com/.../Blogs
which lists the Blogs

then you click on the blog you want to edit posts in and you get this in the address bar
www.mysite.com/.../

notice the %20 after blogposts, this didn't happen prior.

This thread is closed