Aboo Bolaky

{.NET, C#, Sitecore ...} Free your mind...

SEO Friendly Urls in Sitecore -Remove spaces in Url

clock November 29, 2008 00:50 by author Aboo Bolaky

Aliases in Sitecore

Sitecore has the concept of "Aliases", whereby each item can accessed using a specific name (rather than the default path). Aliases are turned on by default. To turn them off, you can flip the web.config settings name AliasesActive to false (But who would want to do that???? Sealed)

Space Characters in Sitecore

When you create an item in Sitecore, you free to choose the naming of your item (provided it succesfully validates against some key rules .e.g Item name cannot contain :,?.. otherwise, you will end up with a "Item xxx is not a valid name"). Most of the time, you will want to put spaces in the item name. Let's take an example:

If an item (at the root level) has an item name of "John Doe", the url of the actual page should theoretically be http://hostname/John%20Doe .

Of course, you can get rid of this spacing issue by specifying an Alias of John-Doe on the item itself. But imaging you having hundreds of items with spaces !!!..

The encodeNameReplacements element in the Web.config

This encodeNameReplacements settings allow you to globally replace any unwanted character in your url to a character of your choice. So, rather than creating an alias for each item (without spaces), we can add the following new setting.

<encodeNameReplacements>

<replace mode="on" find="&amp;" replaceWith=",-a-,"/>

<replace mode="on" find="?" replaceWith=",-q-,"/>

....

<replace mode="on" find=" " replaceWith="-" />

</encodeNameReplacements>

Job Done ! Cool

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Comments

21. October 2009 12:38

Seagaard

OK!

I know that, but I cant figure out what to do when there already are names that contain "-" in the itemname. The items containing "-" fails if I use the obvious solution to replace " " with "-".

Seagaard

Seagaard

10. November 2009 22:38

Aboo Bolaky

You can prevent item names from having the - by adding it to the InvalidItemNameChars in the web.config.

Aboo Bolaky

Add comment


(Will show your Gravatar )  

  Country flag

biuquote
  • Comment
  • Preview
Loading



A b o u t M e

Annoying

Brilliant

Open and

Objective

in every way..
Only Human >>
 
"First learn computer science and all the theory.

Next develop a programming style.

Then forget all that and just hack." Carrette (1990)