Rebuild Name for Web Addresses on steroids
In my experiance it's very common that unexperianced editors very often copies a page in EPiServer from one place to another without changing the url segment.
This behavior can cause the url to very unfriendly and bad from usability point of view.
One example of this is when you create a new page that that deals with a sport of some kind e. g. fooball. The name of the page is then set to Lorem Ipsum and when you save this page EPiServer creates a unique url segment for this page that is not very wellformed e. g. mixing upper and lower cased letters and so on.
After some time the hockey guys decide to create a page of their own and what is more convenient then to copy the football page and just change the main content. This might feel like a very good idea but the result will be something like the image below.
![]()
Not to shabby huh? No seriously, this can be very confusing for the visitor and I think it should be adjusted. EPiServer comes with a admin tool that rewrites all your url segments so you can get rid of the incorrectly named segment "Football1", but unfortunately this tool can create bad segments for your pages e. g. as I mentioned earlier mixing upper and lower cased letters and not removing hyphens correctly.
Having said that, I have created a new admin plugin that according to me creates better url segments for your pages but this does not apply to new pages and it is quite another story.
If you try this relatively untested piece of code I recommend you to create a full backup of your EPiServer database so you can roll back to your previous database if something should go wrong and I take no responsibility for errors that may occur after running this tool.
So feel free to test, evaluate and give me some feedback if you want.
Download here and just drop the assembly in your websites bin directory and you should see a new config tool when you are in admin mode.
This version is compiled against version 5.2.375.236 of EPiServer.
Edit: with better url segments, I mean lower cased letters with no diacritics or double/tripple hyphens.
I feel exactly the same when it comes to the standard URL segments generated by EPiServer. I've got around this problem by listening to the CreatedUrlSegment event of the URLSegment class and replacing those multi hyphens and lower casing the string. I also remove the segment completely for copied pages, by doing a bit of an ugly check for an 1 on the end, which mean that a page will use the page id as segment until the page is re-published which I feel is a fair trade-off.
Included my code below, but I'm not sure how the comment will treat the code below:
Removing the the urlsegment when a page is copied was actually my next step to create wellformed urls so thanks for posting the code. I will certainly return to this issue latar on. Thanks for posting!