How to Properly Test Website Redirections: A Guide for Ensuring Correct URL Routing

How to Properly Test Website Redirections: A Guide for Ensuring Correct URL Routing
Photo by Ludovic Toinel / Unsplash

When managing a website, it's essential to ensure that all variations of your domain URL consistently redirect to your desired primary URL. In this case, the primary URL is https://example.com. Proper redirection not only provides a smoother user experience but also improves SEO by consolidating domain authority.

Imagine you have domain example.com and your boss ask you to use https://example.com as the main URL, not the one with www.

In this guide, we'll walk you through testing common URL variations to ensure that they correctly redirect to your primary URL (https://example.com). The common scenarios we'll focus on are:

  • Redirecting http://example.com to https://example.com
  • Redirecting http://www.example.com to https://example.com
  • Redirecting https://www.example.com to https://example.com

Step 1: Verify the Redirection Setup

First, you need to set up your web server (Apache, Nginx, etc.) to properly handle these redirections. Read this article related to that.

Step 2: Test Redirection Using Browser Tools

You can test one-by-one of your URLs on the browser, and all should go to https://example.com

Step 3: Use Curl for CLI Testing

For a more detailed look at the redirection process, especially for automated or server-side testing, you can use curl from the command line. The curl tool allows you to see HTTP headers and the steps of redirection.

Test redirection from http://example.com, run this curl -I -L http://example.com

Test redirection from http://www.example.com, run this curl -I -L http://www.example.com

Test redirection from https://www.example.com, run this curl -I -L https://www.example.com

Expected Output:

When you run these commands, you should see a sequence of 301 or 302 status codes leading to the final destination URL. For example:

HTTP/1.1 301 Moved Permanently
Location: https://example.com/

This indicates that the redirection is working as expected.

Step 4: Use Online Tools

There are many tools for doing redirection test on the internet. One of my favorite is called httpstatus.io.

Bulk URL HTTP Status Code, Header & Redirect Checker
Redirect checker to easily check status codes, response headers, and redirect chains.

You can do bulk test like this.

Try it yourself.

Finally

Ensuring proper redirection to a single primary URL, like https://example.com, is critical for maintaining a seamless user experience, enhancing SEO, and protecting your website from potential security vulnerabilities related to HTTP. Testing redirection using tools like curl, SEO analyzers or web based online testing service will help ensure that all domain variations behave consistently, bringing users to your desired URL every time.

Hope it helps.

Support Us

Subscribe to Buka Corner

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe