Within Magento you have the option to add URL Rewrites (also commonly called Search Engine Friendly URLs) to make your weblinks more readable to both search engines as visitors. Sometimes issues arise when using these URL Rewrites, for instance when a cache is out-of-date. This guide helps you solve these issues.

System URLs

Within Magento, the URL is built up following strict rules: The URL is built upon with segments, and each segment is separated with a slash (/). The first segment refers to the Magento module that is used to serve the webpage, and the other segments refer to parts within that module. For instance, the following URL might be used for a product:

catalog/product/view/id/177

Here the "catalog" segment refers to the Catalog-module (part of the Magento core), while the other segments indicate that a product with ID 177 should be displayed on the page. A category URL looks similar:

catalog/category/view/id/3

Now, these URLs might be useful to programmers and administrators, but to visitors (and there for search engines) these URLs look like nothing of value. The concept of URL Rewrites allows you to turn these URLs into friendly URLs instead.

Categories and products and their URL Key

Within each category or product there is a field called URL Key. The value of this field is used to build the friendly URL. It is there for recommended to always enter something useful here. Also note that the URL Key needs to be unique for all your products.

The easiest way to come up with a good URL Key is to take the products title and translate it into a code which is allowed for URLs: This includes alphabetical characters (a till z, preferably lowercase), numerical characters (ehm, numbers) and some extra characters (-_,.).

my-friendly-url

The URL Key is stored with the product properties, but also in a separate listing of URL rewrites. This listing can be managed through Catalog > URL Rewrite Management, which allows you to overwrite the default generated values, for instance per Store View when dealing with multilinguality.

If you remove the entries from URL Rewrite Management, the SEF URLs pointing to your product will become invalid. As soon as you refresh the URL Rewrites index (see below), Magento will check for corresponding URL Rewrite entries and create them if necessary.

System Configuration options

Within the Magento configuration (accessed in the Magento Admin Panel through System > Configuration) there are some relevant settings that determine what the eventual Search Engine Friendly URL looks like. Let's take a look at some of them.

  • Web > Search Engine Optimization > Use Web Server Rewrites
    A setting which should always be turned on. If not "/index.php/" will be added to URL which is unnecessary and looks ugly. To enable this option, you also need Apache mod_rewrite enabled in your hosting environment.
  • Catalog > Search Engine Optimizations > Product URL Suffix
    The default value here is ".html" which will be appended to each product URL. Some SEO-experts claim this is needed for better rating, other SEO-exports say it is not. For our MageBridge integration with Joomla! this setting needs to be empty.
  • Catalog > Search Engine Optimizations > Category URL Suffix
    The same as above, but now categories.
  • Catalog > Search Engine Optimizations > Use categories path for product URLs
    With this option enabled, the product URL will also include the category URL Keys. While it could be argued this causes duplicate content, product pages might also benefit from this because they become part of a bigger structure.
  • Catalog > Search Engine Optimizations > Use Canonical Link Meta Tag For Products
    If you are really worried about duplicate content (which is not as bad as some people will tell you), then you can enable the canonical tag which tells search engines which page is leading once duplicate content has been detected.
  • Catalog > Search Engine Optimizations > Use Canonical Link Meta Tag For Categories
    The same as above, but for categories.

Of course more settings are related to SEO, looking at how important content in general is, but in this guide we stick to the URL settings.

Don't forget to re-index the Catalog URL Rewrites

magento_reindex_url_rewrites

As soon as you make changes in the System Configuration, or you remove entries from the URL Rewrite Management page, you'll also need to refresh the Catalog Url Rewrites index. With Magento 1.4 you can browse to System > Index Management and select the Catalog Url Rewrites to refresh them.

Fixing weird URL Rewrites

Sometimes when you make changes to your products, or enable a certain extension, Magento might start to rewrite all your URLs to include a suffix "-1" or some other number. Within the URL Rewrites, Magento differentiates between System URLs and Custom URLs. If the System URLs are broken like this, you should not fix this by adding new Custom URLs.

Instead, open up phpMyAdmin, create a backup of your Magento database, and flush the Magento table core_url_rewrite (so that it becomes totally empty). Immediately afterwards, refresh the Catalog Url Rewrites under Index Management. This will regenerate all System URLs.