Redirect Examples

Posted by

For each of the examples on this page we will only cover the fields that make the redirect perform as described. Fields such as Label, Enabled etc. which have no impact on the outcome of the redirect will not be mentioned anywhere.

Important: It is possible to setup redirects in a way that cause the URL being targeted, and sometimes a whole website, to not load. If a URL triggers a redirect, and the user is sent to another URL which also triggers that same redirect, the redirect will be triggered continually until the browser detects a redirect loop, at which point the browser will simply display an error. For redirects where a minor mistake can cause this to occur we have added an "Important:" section. Pay close attention to these.

Terminology and Basic Instructions

Before reviewing the examples below it's important to understand the different parts of a URL, what they're called, and which fields to use to set the values requires to trigger the redirect.

http://   www.mintox.com   /contact-us   ?isnew=1

 
Protocol
: The protocol is the HTTP:// or HTTPS:// at the start of the URL. To set the protocol required to trigger a redirect, use the Protocol field.
Domain: The domain follows the protocol, it is www.mintox.com in this example. To set the domain required to trigger a redirect, use the Domain field.
Request Path: The request path, if present, follows the domain and always starts with a /, it is /contact-us in this example. To set the request path required to trigger a redirect, use the Redirect From field.
Query String: The query string, if present, will follow a ? at the end of the request path, it is isnew=1 in this example. To include the Query String when deciding if the URL should be redirected, check the "Match query string and path info" box, then include the required query string information in the Redirect From field.

When a URL "matches" a redirect, it means the URL has met all the criteria specified by the Protocol, Domain and Redirect From fields, and the redirect will occur.

Force WWW

If your website loads both with and without the WWW at the start this can have a negative effect on SEO, so it's common practise to force the website to load only with the WWW or without the WWW, but not both. This is a highly recommended redirect which is generally implemented from the start. For this example, we will be forcing the website to load at WWW.

Domain: Select the option which does NOT have www. at the start.
Use Regular Expressions: Check the box.
Redirect From: Enter "^(.*)$" without the quotes, this means anything or nothing. For a URL to trigger this redirect, the request path can be anything or unspecified. For example, http://mintox.com, http://mintox.com/ and http://mintox.com/contact would all trigger the redirect.
Redirect To: Enter your full domain name including http://www. or https://www. at the start and at the end of the domain type simply add $0. For example, if this were mintox.com we would use http://www.mintox.com$0, think of the $0 as a placeholder containing the request path from the original request.

Important: When the domain is set to the non-WWW domain and the Redirect From is set to (.*), this redirect will match any request to your non-WWW domain. To prevent a redirect loop, which takes down your website, ensure you include www. at the start of the domain in the Redirect To field.

Force HTTPS

If your website has an SSL certificate then it can load by either HTTP or HTTPS. Generally, such websites will always load in HTTP until a page that requires HTTPS is accessed, such as the checkout on shopping cart sites. In this example we force the entire website to only load via HTTPS.

Protocol: http
Use Regular Expressions: Check the box.
Redirect From: Enter "^(.*)$" without the quotes, this means anything or nothing. For a URL to trigger this redirect, the request path can be anything or unspecified. For example, http://mintox.com, http://mintox.com/ and http://mintox.com/contact would all trigger the redirect.
Redirect To: Enter your full domain name including https:// at the start and at the end of the domain type simply add $0. For example, if this were mintox.com we would use https://www.mintox.com$0, think of the $0 as a placeholder containing the request path from the original request.

Important: When the protocol is set to HTTP and the Redirect From is set to (.*), this redirect will match any request to your domain via http://. To prevent a redirect loop, which takes down your website, ensure you include https:// at the start of the domain in the Redirect To field.

Renamed Top-Level Product Categories or Web Pages - Using 1 Regex Placeholder

When websites are built, the initial top level content such as the main web pages on the menu, the broad top level product categories, news categories etc. can often become a part of the URLs of all the content that follows. The most common example of this is shopping cart websites, there is often a broad top level category, such as Clothing, which contains many sub-categories of clothing, each with hundreds or thousands of products.

After this content has been around for some time it will be indexed by search engines such as Google, and bookmarked by users interested in the products. What the search engines and users have recorded is the URL of that page at the time they viewed it.

Now, in the above example what if you need to rename the top level category Clothing to Apparel? You can easily change it through Mintox, but you also know that will change the URL of the Apparel category page, as well as the URL of every product and sub-category below it. This would result in the links indexed by search engines and bookmarked by users becoming invalid, and a Page Not Found message would be shown when clicking those links or bookmarks. You need to ensure that when a user goes to the old URL with Clothing in it, the user is redirected to the new URL with Apparel in it.

For this example, let's pretend this is a small portion of old and new URL structure:

Old URL Structure:

/products/Clothing
/products/Clothing/Shirts
/products/Clothing/Jackets
/products/Clothing/Hoodies
/products/Clothing/Trousers
/products/Clothing/Jeans

 

New URL Structure:

/products/Apparel
/products/Apparel/Shirts
/products/Apparel/Jackets
/products/Apparel/Hoodies
/products/Apparel/Trousers
/products/Apparel/Jeans

To setup this redirect, we would do the following:

Use Regular Expressions: Check the box.
Redirect From: Enter "^/products/Clothing(.*)$" without the quotes, this means the request path must start with /products/clothing and be followed by anything or nothing to trigger the redirect. For example, http://www.mintox.com/products/clothing and http://www.mintox.com/products/clothing/shirts would both trigger this redirect.
Redirect To: Enter "/products/Apparel$1" without the quotes, this will redirect users to /products/apparel followed by whatever followed /products/clothing in their original request. For example, http://www.mintox.com/products/clothing would redirect to http://www.mintox.com/products/apparel and http://www.mintox.com/products/clothing/shirts would redirect to http://www.mintox.com/products/apparel/shirts.

In the first two examples we saw that $0 is a placeholder for the full request path from the original request. $1 is different, it is a placeholder for the text from the original request that matched the (.*), or in other words, it contains the text that followed /products/clothing (only because the (.*) followed /products/clothing).

Removing Old Product Lines - Using 1 Regex Placeholder, some 1-to-1 redirects and ordering.

On large shopping cart websites there are many categories, each with many sub-categories. Sometimes it is necessary to delete some, but not all, of those sub-categories from a particular category, such as certain product types no longer being available, or choosing not to sell those products any more. For this example, pretend you have a top level category called Clothing on your website with a variety of sub-categories, but you have decided to only sell Jackets and Hoodies from now on, and instead of keeping them under Clothing you want to move them to the top-level, like this:

Old URL Structure:

/products/Clothing
/products/Clothing/Shirts
/products/Clothing/Jackets
/products/Clothing/Hoodies
/products/Clothing/Trousers
/products/Clothing/Jeans

 

New URL Structure:

/products/Jackets
/products/Hoodies

As usual, we need to ensure requests to the old URLs are captured and sent to the correct location. For this example, we need to catch requests for the Jackets and Hoodies categories and send them to the new URLs, but for anything else we need redirect them to the home page.

We cannot just use the solution in the previous example because our three redirect destinations ( /, /products/Jackets and /products/Hoodies ) have 2 distinct URL patterns instead of just 1 like in the above example. While it is possible to write regex to handle such situations in a single redirect, it is complex and won't be covered here. Instead, we need to make 2 redirects and run them in a certain order.

The first redirect will match either /products/Clothing/Jackets or /products/Clothing/Hoodies, and if the URL matches then the user will be sent to /products/Jackets or /products/Hoodies as appropriate. The second redirect we add is a catch-all, which will grab any request to /products/Clothing and send it to the home page. The ordering is very important here, we run the Jackets/Hoodies specific redirect first because if the URL matches then the second catch-all redirect won't be checked. Only if the the first redirect doesn't match will the catch-all kick in. If we ran the catch-all redirect first, it would match the Jacket/Hoodies URL and redirect those requests to the home page instead of the new URL for those categories.

For the Jackets/Hoodies specific redirect:
Use Regular Expressions: Check the box.
Redirect From: Enter "^/products/Clothing/(Jackets|Hoodies)$" without the quotes, this means the request path must start with /products/clothing and be followed by either Jackets or Hoodies to trigger the redirect. For example, only http://www.mintox.com/products/jackets and http://www.mintox.com/products/clothing/hoodies will trigger this redirect.
Redirect To: Enter "/products/$1" without the quotes, this will redirect users to /products/ followed by whatever followed /products/clothing in their original request. For example, http://www.mintox.com/products/clothing/jackets would redirect to http://www.mintox.com/products/jackets and http://www.mintox.com/products/clothing/hoodies would redirect to http://www.mintox.com/products/hoodies.

With the Jackets/Hoodies specific redirect in place we can move onto the catch-all redirect.
Use Regular Expressions: Check the box.
Redirect From: Enter "^/products/Clothing(.*)$" without the quotes, this means the request path must start with /products/clothing and be followed by anything or nothing to trigger the redirect. For example, http://www.mintox.com/products/clothing and http://www.mintox.com/products/clothing/shirts would both trigger this redirect.
Redirect To: Enter "/" without the quotes, this will simply redirect users to the home page.

Redirects are automatically run in the order they're added in, but you can re-order them as you wish. If they were added in order then the redirects are finished, however if you're unsure or would just like to check, go back to the main URL Redirects page. You'll see a list of redirects including the two you just added, on the right you'll see the re-arrange icon which is 2nd from the right. Click and drag this icon to drag the entire redirect to a new position in the execution order.

 

Modified News URL Structure - Using 2 Regex Placeholders

Some components, such as news and products, dynamically generate URLs for all their content based on category, news and product names. The structure of this URL can be customised for News, you can choose to include information such as the category name, article name, date added, month added etc.

The initial setting for the News URLs is /news/article/{day}{month}{year}-{category name}/{article name}.aspx which ensures a unique URL is generated. Now, let's say you've developed a very popular blog and people know it by name, and you want to update the URLs of your articles to reflect the name that your readers know. You decide to modify your News URL structure to: /my-health-blog/{day}{month}{year}/{article name}.aspx.

The next step is to make sure anyone who visits an older URL is redirected to the new URL, and for this example our aim is to transform /news/article/01062016-fitness/keeping-fit-over-christmas.aspx into /my-health-blog/01062016/keeping-fit-over-christmas.aspx.

Use Regular Expressions: Check the box.
Redirect From: Enter "^/news/article/(.+)-(.+)/(.+).aspx$" without quotes, this means the request path must:

  • start with /news/article/, followed by
  • anything but not nothing (difference between (.*) and (.+) ), followed by
  • a dash, followed by
  • anything but not nothing (difference between (.*) and (.+) ), followed by
  • a slash, followed by
  • anything but not nothing (difference between (.*) and (.+) ), followed by
  • .aspx

For example, /news/article/01062016-fitness/keeping-fit-over-christmas.aspx would, of course, trigger this redirect. However, the following would not:

  • /news/article/-fitness/keeping-fit-over-christmas.aspx
  • /news/article/01062016-/keeping-fit-over-christmas.aspx
  • /news/article/01062016-fitness/.aspx
  • /news/article/-/.aspx

Redirect To: Enter "/my-health-blog/$1/$3.aspx" without the quotes, this builds the new URL as follows:

  1. Starts with: /my-health-blog/
  2. Then $1 is inserted and replaced with the value of the first (.+), which in our example is: 01062016
  3. Then we insert: /
  4. Then $3 is inserted and replaced with the value of the third (.+), which in our example is: keeping-fit-over-christmas
  5. Lastly, we add .aspx to the end

Which results in: /my-health-blog/01062016/keeping-fit-over-christmas.aspx

If you wanted to include the category in the URL you could simply include $2 in the Redirect To field as well. For example, if we used "/my-health-blog/$1/$2/$3.aspx" as in the Redirect To field, our redirect would result in: /my-health-blog/01062016/fitness/keeping-fit-over-christmas.aspx

 

Do you need to setup a redirect that we haven't covered here? Contact support and we will be happy to help you.

Category: Web Pages