URL Formatting

Format URLs to Web pages the way you want

In C1 CMS, URLs to web pages have the following model:

http[s]://<host name>[/<language code>]/<path to a page>

where <path to a page> is built by appending the "UrlTitle" fields of pages and their ancestors: <Level1Page UrlTitle>/<Level2Page UrlTitle>/.../<CurrentPage UrlTitle>

For example:

  • http://www.contoso.com/MyPage
  • http://www.contoso.com/Products/Product-A/Features
  • http://www.contoso.com/da-DK/Products/Product-A/Features

URL Formatting Rules

You can control how the <path to a page> part of the URL is built from the "UrlTitle" fields by applying one or more rules when a pages is added or edited.

For example, you may want to have the space character (' ') replaced with a dash ('-'): "Hello World" (UrlTitle) > "Hello-World" (Title).

The rules can be set as mandatory or optional.

For example, replacing ' ' with '-' can be set as mandatory and converting characters to lowercase can be set as optional.

The rules are applied when the user adds a page and when the user edits a page.

  1. When the user adds a page, the UrlTitle field will get its value from the Title field with the rules applied, regardless whether they are mandatory or optional. In our example, both replacing ' ' with '-' and converting to lowercase will be applied turning "Hello World" into "hello-world".
  2. When the user edits a page and then tries to save it, the mandatory rule will be automatically applied, and there will be a message box saying that UrlTitle was updated.
    The optional rule in this case will no longer be applied. In our example, if the user changes "hello-world" to "Hello-World", the page will be saved with this new UrlTitle.

Configuration

The rules are defined in /App_Data/Composite/Composite.config

It has the following structure:

<configuration>
  <Composite.Core.Urls defaultPageUrlProviderName="Default">
    <PageUrlProviders>
      <add name="Default" type="Composite.Plugins.Routing.Pages.DefaultPageUrlProvider, Composite" />
    </PageUrlProviders>
    <UrlFormatters>
      <add name="StringReplace" type="Composite.Plugins.Routing.UrlFormatters.StringReplaceUrlFormatter" mandatory="true">
        <ReplacementRules>
          <add oldValue=" " newValue="-" />
          <add oldValue="?" newValue="" />
          <add oldValue="#" newValue="" />
        </ReplacementRules>
      </add>
      <!--add name="LowerCase" type="Composite.Plugins.Routing.UrlFormatters.ToLowerCaseUrlFormatter" mandatory="false" /-->
      <add name="Aplhabets" type="Composite.Plugins.Routing.UrlFormatters.StringReplaceUrlFormatter" mandatory="true" rulesFile="~/App_Data/Composite/Configuration/UrlFormatting.xml" />
    </UrlFormatters>
  </Composite.Core.Urls>
</configuration>
The rules are specified within the <UrlFormatters> section as URL formatters. Each URL formatter is added with the <add/> element and must specify these attributes:

  • name: The name of the URL formatter. (If the formatter is used several times it must have different names.)
  • type: The type used to format the URLs.
  • mandatory: When "true", the rules defined by the formatter are mandatory; otherwise ("false"), optional.

If necessary (for example, a lot of rule entries), the rules can be moved to an external file. The file must be placed in /App_Data/Composite/Configuration/ and specified in Composite.config in this attribute:

  • rulesFile: The path to the file that contains specific rules for an URL formatter.

For example: /App_Data/Composite/Configuration/UrlFormatting.xml

The root element of this file should be <ReplacementRules/>. (See the description of the StringReplaceUrlFormatter for more information about the syntax.)

URL formatters

By default, C1 CMS has these URL formatters available for use:

  • ToLowerCaseUrlFormatter
  • StringReplaceUrlFormatter

ToLowerCaseUrlFormatter

ToLowerCaseUrlFormatter converts all uppercase characters to lowercase. Example: "Hello-World" > "hello-world".

It is used as a single element:

<add name="LowerCase" 
type="Composite.Plugins.Routing.UrlFormatters.ToLowerCaseUrlFormatter" 
mandatory="false" />

In theComposite.config this URL formatter element is commented out. If you want to apply this rule, uncomment it. By default, this rule is set as optional.

StringReplaceUrlFormatter

The StringReplaceUrlFormatter can be reused for various use cases. Its specific replacement rules are defined within the <ReplacementRules> element with the <add/> elements that require the following attributes to be set:

  • oldValue: the character(s) to be replaced
  • newValue: the character(s) to replace with

There are 2 string replacing rules defined with StringReplaceUrlFormatter.

  • "Special Characters"
  • "Alphabets"

"Special Characters" replaces all spaces (' ') with dashes ('-') as well as removes all '?' and '#'. Example: "Hello World" > "Hello-World".

<add name="StringReplace" type="Composite.Plugins.Routing.UrlFormatters.StringReplaceUrlFormatter" mandatory="true">
  <ReplacementRules>
    <add oldValue=" " newValue="-" />
    <add oldValue="?" newValue="" />
    <add oldValue="#" newValue="" />
  </ReplacementRules>
</add>

"Alphabets" replaces non-ANSI characters ('extended Latin' and 'Cyrillic') with their ANSI representations. Example: "Rækker" > "Raekker" or "Продукты" > "Produkty".

It is defined in Composite.config:

<add name="Alphabets" 
type="Composite.Plugins.Routing.UrlFormatters.StringReplaceUrlFormatter" 
mandatory="true" 
rulesFile="~/App_Data/Composite/Configuration/UrlFormatting.xml" /> 

Its rules are kept in a separate file: /App_Data/Composite/Configuration/UrlFormatting.xml.

<ReplacementRules>
  <!-- Extended latin -->
  <add oldValue="å" newValue="aa" />
  <add oldValue="æ" newValue="ae" />
  <add oldValue="ø" newValue="oe" />
  <add oldValue="ä" newValue="ae" />
  <add oldValue="ö" newValue="oe" />
  <add oldValue="ü" newValue="ue" />
  <add oldValue="ß" newValue="ss" />
  <add oldValue="Å" newValue="Aa" />
  <add oldValue="Æ" newValue="Ae" />
  <add oldValue="Ø" newValue="Oe" />
  <add oldValue="Ä" newValue="Ae" />
  <add oldValue="Ö" newValue="Oe" />
  <add oldValue="Ü" newValue="Ue" />
  <!-- Cyrillic alphabet -->
  <add oldValue="а" newValue="a" />
  <add oldValue="б" newValue="b" />
  <add oldValue="в" newValue="v" />
  <!-- skipped for readability. See UrlFormatting.xml for the full list -->
  <add oldValue="Я" newValue="Ja" />
  <add oldValue="Ґ" newValue="G" />
  <add oldValue="І" newValue="I" />
  <add oldValue="Ї" newValue="Ji" />
</ReplacementRules>

Requirements

C1 CMS version 3.0 or later