343: How to alter the format of SEF URLs in PrestaShop 1.5

When using SEF URLS in your PretaShop 1.5 store, you may not like the default format. For example, the format for a product is as follows: category/idrewrite-textean13.html. This URL comes from different variables strung together to give you a more human-readable format. There are four parts to the URL as shown by the color differences in the text. Below is a table displaying the separate sections:

KeywordSample CodeDescription
categorymusic-ipodsThe category under which the product is listed.
id1The unique product ID number in the database.
rewrite textipod-nanoThsi comes from the friendly URL field under the SEO tab of the Product Edit page.
ean13123This comes from the ean13 or JAN field from the Information tab of the Product Edit page.

Why change the format?
The friendly URL for an ipod nano using the sample code for each section above will be https://prestashop.inmotiontesting.com/en/music-ipods/1-ipod-nano-123.html. This URL may not suit your tastes and you may want to arrange it differently for your customers. Perhaps you want to remove the ean13 number, or move the product ID to the back, or make it appear as its own category separated by slashes. Unfortunately, you cannot remove the id entirely from the URL as it is required by PrestaShop’s core coding.

Formatting Syntax
The default URL format is {category:/}{id}-{rewrite}{-:ean13}.html. The syntax is fairly straight forward, each keyword is enclosed in a set of curly braces like {}. You can add a slash (/) or a dash (-) in between keywords (outside the curly braces) to add them to the URL. For example: {category}/{id}-{rewrite} will result in category/id-rewrite. You may also notice the use of the colon (:) character. This is used within a keyword when adding a slash or a dash. {category :/} results in category/. You can use either method to add dashes or slashes. Below we will change the default URL format for our ipod nano to be more visitor friendly.

Modifying your SEF URL format in PrestaShop 1.5

  1. Log into your PrestaShop admin dashboard.
  2. Using the toolbar across the top of the page, hover over the Preferences tab and then click on the SEO & URLs option from the popup menu.
  3. Once on the SEO & URLs page, scroll down until you get to the section labeled Schema of URLs. Although there are many fields to work with, we will work with the first one, Route to products. In our example, we will remove the ean13 number from the URL by removing the keyword tag {-:ean13}. We also will add a slash instead of a dash between the product ID and the rewrite text. To do this we enter the code in the field as {category:/}{id}/{rewrite}.html
    new url format coding

  4. Once you have your desired format in place, click the green Save button in the upper right corner to save the changes. Below you can see the before and after shots for the URL formatting change.

    BeforeAfter
    format: {category:/}{id}-{rewrite}{-:ean13}.htmlformat: {category:/}{id}/{rewrite}.html
    before url formatting change

    after SEF URL format changes

Was this article helpful? Join the conversation!