Dhanuka777
Dhanuka777

Reputation: 8616

Sitecore - Manipulating URL's

Sitecore generates URL's based on the item names defined in the Sitecore tree,

http://samplewebsite/Pages/Sample Page

But our client is interested to lower the case of all URL's (pages/sample page), and format the blank spaces with hyphen (sample-page).

How can I do this?

Upvotes: 3

Views: 5862

Answers (4)

Jon-YYC
Jon-YYC

Reputation: 187

If you are using a custom config file in App_Config/Include you can use the following config patches between your <sitecore> and </sitecore> tags. This will change spaces to dashes in your URL and not allow content editors to use dashes in their item names.

<encodeNameReplacements>
  <!-- Replace spaces in URLs with dashes -->
  <replace mode="on" find=" " replaceWith="-" />
</encodeNameReplacements>
<settings>
  <setting name="InvalidItemNameChars">
    <!-- Disallow dashes in item names for content editors because the above rule causes the page to crash -->
    <patch:attribute name="value">-\/:?&quot;&lt;&gt;|[]</patch:attribute>
  </setting>
</settings>

Upvotes: 2

Trayek
Trayek

Reputation: 4410

In your web.config, you can add <replace find=" " mode="on" replacewith="-"> in the <encodeNameReplacements> node to format spaces with hyphens. Be careful though - that will mean you aren't able to use hyphens in item names anymore (as Sitecore will try and find an item with a space in it)

To lower-case your URLs you could use the rule engine, like John West describes here:
Use the Sitecore Rules Engine to Control Item Names

Upvotes: 9

Marek Musielak
Marek Musielak

Reputation: 27132

Space to hyphen replacement can be done with <encodeNameReplacements> part of Sitecore.config.

To use lowercase characters for all of urls, you need to extend LinkManager class. Both of them are explained here:

http://csuwannarat.wordpress.com/2011/07/17/how-i-make-seo-friendly-sitecore-urls/

Upvotes: 1

Related Questions