Redirects can be used to catch requests made to one or more URLs and redirect the user to a different URL. This is helpful when content is renamed, moved or deleted, or if you completely change your website structure or domain name and need to send all requests to a new location.
If you would like to setup some redirects, click the URL Redirects button in the Web Pages component and read on.
There are 2 methods for adding redirects, Quick Add and the full Add Redirect page. Quick Add is useful for simple 1-to-1 redirects where 1 specific URL is redirected to another specific URL, and the full Add Redirect page includes extra details and functionality allowing for more complicated redirects.
As mentioned above, Quick Add is useful for simple 1-to-1 redirects, so for this example we will setup a redirect that catches all requests to the path /redirect-me on your domain and redirect the traffic to your home page.
To start with, navigate to the home page of your website and add /redirect-me to the end of the URL and press enter, the page that loads will say the requested page could not be found. Now, back into Mintox:
- Label: Enter a name for this redirect. For this example you could enter Redirect /redirect-me to /
- Protocol: If you want this redirect to only apply when the website is loaded by either HTTP or HTTPS, choose the appropriate option from the drop down menu. Otherwise, using the Any option will cause the redirect to apply regardless of the protocol used. For this example, Any is fine.
- Domain: The majority of websites will have 2 domains, one with www. at the start and one without. If you want this redirect to only apply to a specific domain name, select it, otherwise leave All Domains selected and the redirect will apply regardless of the domain. For this example, leave All Domains selected.
- Redirect From: This is the requested path to be redirected, enter /redirect-me
- Redirect To: This is where the requested path should be redirected to, enter /
- Redirect Type: Normally you would select 301 (Permanent) but for this example select 307 (Temporary).
Click on Quick Add and the redirect is now in place.
Now navigate to the home page of your website again and add /redirect-me to the end of the URL and press enter. This time you won't see the same error message, you will instead be redirected to the home page of your website. After you've finished experimenting with this feature and the redirect you added, you should either disable or delete the redirect.
Full Add Redirect Page
One of the key differences on the main Add Redirect page is the ability to setup a redirect using Regular Expression (regex), think of it as a tool you can use to catch requests to more than just 1 specific URL. Using regex you can catch requests to a very large number of URLs and redirect them all to a different URL based on the requested URL.
We'll just cover a basic regex example here, if you would like further information on regex or regex examples refer to Redirect Examples.
Let's say you have a Product Category on your website with many products and sub-categories below it, the URL of the category is: /products/clothing
You have decided to stop selling clothing on your website and you plan on deleting the clothing category. However, you know that users have bookmarked some of the products in the clothing category and sub-categories, and you know some of these pages have also been indexed by search engines. You don't want users going to the bookmarked or indexed URLs to see a Page Not Found message, instead you want them to be redirected to the home page.
This can be done with a single redirect by using regex. Click on Add Redirect and complete the following fields:
- Label: Enter Clothing Category Redirect
- Protocol: Leave this on Any.
- Domain: Leave this on All Domain.
- Use Regular Expressions: Check this box.
- Match Query String and Path Info: Leave this unchecked for this example. This field can be used to match not only the requested path but also the query string. If you see a ? near the end of a URL followed by something=somevalue, that is a query string.
- Include Query String and Path Info: This can be used to include the original query string at the end of the new URL. Leave this checked for this example.
- Redirect Type: Select 301 (Permanent), unless this is just a test, in which case choose 307 (Temporary).
- Enabled: Leave this checked if you want the redirect to take effect after it is saved.
Lastly, the regex needs to be setup. Click on Build and Test Regular Expressions and follow these steps:
- Input Data: This is test data and does not change the effect of the redirect. For our example, type in "/products/clothing" without quotes.
- Regex From Pattern: This is the regex pattern that the URL must match before the redirect will be triggered. Type in "^/products/clothing(.*)$" without quotes.
- Test Matches: Clicking this button will test the Input Data against the Regex From Pattern, click the button now and you will see the following appear:
Next, change the input data to "/products/clothing/tshirts/plain-red-shirt.aspx" without quotes and click Test Matches again. You will now see:
To keep this article simple we won't completely explain the functionality here, we'll leave that for the Redirect Examples article. If you're results match what is shown above, continue.
- Regex To Pattern: This is where we build the URL that the user is redirected to. Since we want to send users to the home page, simply put a forward slash ( / ) into this field. Note: This is quite literally where you build the new URL, you can type in any text you wish, but you can also type in $0), $1), $2) etc. to insert portions of text from the original URL.
- Test Result Pattern: Clicking this button will display which URL the user will be redirected to if they go to the URL specified in the Input Data field. Since we are just redirecting to the home page, the Result Pattern field below should simply show a /.
- Click Update to close the window and move the Regex From and To Patterns to the main page.
Back on the main Add Redirect page, click on Save and the redirect will will become active. Now, navigate to your home page and add any of the following to the end of the URL:
After attempting to go to the URL, you will be sent to the home page of your website instead. This type of redirect isn't limited to redirecting to the home page though, that was just to keep the example simple, but there's much more you can achieve using regex. For more information be sure to look at the Redirect Examples.