URL Redirects

From Spiffy Stores Knowledge Base

URL Redirection allows you define a set of URL patterns that will be used to match against all incoming URL addresses for your store, and when a match is found, the URL request will be redirected to a new target URL of your choosing.

A URL or Uniform Resource Locator is the string of data that identifies the pages on your Spiffy Store. Each URL is made up of the domain name, prefixed by either http:// or https:// followed by the actual address of the pages.

A URL containing the prefix and the domain name is called an Absolute URL, whereas a URL consisting of just the page address is called a Relative URL.

For example, this is an Absolute URL

http://mystore.spiffystores.com/collections/shirts

and this is a Relative URL

/collections/shirts

What are URL Redirects?

If you are creating your store from scratch, then you won't need to use any URL redirects. This feature is only useful to store owners who are migrating their stores from a different software platform and who want to maintain the old links that may have been cached by search engines.

If you have migrated your store then it is likely that the structure and naming conventions for your products, collections and pages will have changed. It may take some time for search engines to update their search results, so you may run into the problem of having your customers click on search engine links which will link to an old URL that does not exist in your new store. The result will be that the customer will get a page not found error and this may cause them to give up and search elsewhere.

URL Redirects can solve this problem by simply defining a mapping for all the old URLs to new target URLs that will map the links to the equivalent products and pages in your new store.

Adding a new URL Redirect

A URL redirect can be created in the Marketing -> URL Redirects section of your Store's Toolbox.

  1. Click on the add a redirect button
  2. Enter an Old Path such as "/shirts" or "/reviews"
  3. Enter your Target Path
  4. Click Save Redirect.

The Old Path must be a Relative URL representing the incoming URL address that must be matched.

The Target Path is the new URL for the matched address and it can be either a Relative URL to point to a page on the current store, or it can be a full Absolute URL including the domain name to redirect the URL to a different domain name and web site.

Here are some examples of valid URL redirects.

Old Path                   Target Path
/index.php                 /
/product.php?id=shirt      /products/shirt
/search.html               http://www.google.com

Pattern Matching

The Old Path value is used as a pattern to match URL requests, and it may be extended using Regular Expressions to provide very powerful wildcard capabilities.

Without the use of patterns, it would be necessary to create a redirect for every possible URL that can be generated, and this can sometimes mean that you would have to create many thousands of redirect records. Quite often, these thousands of redirects can be replaced by a handful of patterns, saving countless hours of work to generate and import all the redirects.

At its simplest, the Old Path string is used as a pattern match and if the incoming URL equals the string, then a match has been found.

The pattern is always matched against the start of the incoming URL, so the pattern can not be used to match against trailing strings. Also, the pattern will match against the start of a string and will automatically match all trailing characters.

For example,

'/product' matches '/product'
'/product' does not match '/test/product'
'/product' matches '/product/shirt'
'/product' matches '/product/shirt?size=20'

If you only want to match an exact string, then a '$' character must be added at the end of the pattern.

'/product$' matches '/product'
'/product$' does not match '/product/shirt'

Regular Expressions in URL Patterns

The full power of Regular Expressions can be used in the URL patterns specified in the Old Path field.

All patterns specified act as if they have the regular expression character '$' appended to the pattern to ensure that it always matches the start of the string. It is not necessary to specify a '$' character at the beginning of any pattern.

Basic Concepts

A regular expression pattern contains sequences of characters which match themselves except for the following special characters -

. | ( ) [ ] { } + \ ^ $ * ?

The vertical bar '|' specifies alternatives and parentheses '(' and ')' are used to group expressions together.

'I have a pet (dog|cat) at home' matches 'I have a pet dog at home'
'I have a pet (dog|cat) at home' matches 'I have a pet cat at home'

The '.' character matches any character.

Repetition

You can specify a quantifier after a character or a group to indicate how many times that character or group is repeated.

* 	a sequence of 0 or more matches of the item
+ 	a sequence of 1 or more matches of the item
? 	a sequence of 0 or 1 matches of the item
{m} 	a sequence of exactly m matches of the item
{m,} 	a sequence of m or more matches of the item
{m,n} 	a sequence of m through n (inclusive) matches of the item; m may not exceed n

For example,

'colou?r' matches both 'color' and 'colour'
'ab*c' matches 'ac', 'abc', 'abbc', 'abbbc', and so on
'ab+c' matches 'abc', 'abbc', 'abbbc', and so on, but not 'ac'

Anchors

The '^' character matches the start of the string. This is implied in all URL redirect patterns and does not have to be specified.

The '$' character matches the end of the string. This forces the pattern to match the string exactly, and excludes matching only part of the string.

Character Classes

A character class is a set of characters enclosed in brackets '[' and ']'. A pattern using character classes will match a character with any one of the characters in the class.

'[aeiou] is a vowel' matches 'e is a vowel'
'[aeiou] is a vowel' does not match 'x is a vowel'

The character class can be negated by prefixing the characters with a '^'.

'[^aeiou] is not a vowel' does not match 'e is not a vowel'
'[^aeiou] is not a vowel' matches 'x is not a vowel'

Ranges of characters can also be specified.

'[a-zA-Z0-9]' matches all upper and lowercase letters and numbers

If you need to include one of the special characters in the list, the you can escape it by prefixing the character with a '\'.

Examples

Here are some examples on how to construct URL Redirect patterns.

Old Path                            Target Path
'/products/toys/educational.html'   '/collections/educational-toys'
'/products/toys.html'               '/collections/toys'
'/catalogsearch'                    '/search'
'/products/clothes/(girl|boy).html' '/collections/kids-clothes'
'/index.php'                        '/'
'/catalog.php?id=(.+)&type=shirt'   '/product/shirt'

Further Reading

This is a brief summary of the Regular Expression syntax that can be used to build URL Redirect patterns.

If you need further information on how to build more complex patterns, then please refer to the following documentation: