Skip to main content

How to redirect users on the Web?

Summary

Redirects are essential for maintaining user experience and search engine rankings when a web page is moved, renamed, or deleted. Learn about server-side redirects, HTTP status codes, meta redirects, and CNAME redirects at the DNS level.

Introduction #

Redirecting users is necessary when a web page is moved, renamed, or deleted to ensure users can still access the intended content without encountering errors. Making use of redirects dramatically enhances the user experience. It may also help to maintain search engine rankings and link equity by forwarding traffic from old URLs to updated ones.

HTTP Redirection (Server-side Redirects) #

HTTP redirection involves HTTP status codes, which are sent by the server to inform the client, e.g. a Web browser, that a resource has been moved and specify its new location. Common redirect codes include 301 (Permanent Redirect) for permanent changes and 302 (Temporary Redirect) for temporary moves, guiding how browsers and search engines handle the redirected URL. However, there are more redirection HTTP status codes. For even more information see the full list of HTTP status codes.

Adjust the status code in the examples below as needed.

In an Apache .htaccess file:

Redirect 301 /old-page.html https://example.com/new-page.html

Nginx servers:

server {
  location /old-page.html {
    return 301 https://example.com/new-page.html;
  }
}

You can also trigger HTTP redirects from within documents.

In PHP:

header("Location: https://example.com/new-page", true, 301);
exit();

Meta Redirects (HTML-based Redirects) #

If you do not have access to the server that hosts your old web page, you might fall back to using this method, which can be disruptive to users.

Placed in the <head> section of the HTML document /old-page.html, this method instructs the browser to redirect after a delay.

<meta http-equiv="refresh" content="5;url=https://example.com/new-page.html">

Replace 5 with the number of seconds to delay the redirect, use 0.

You could also provide instructions for users in the document body about where exactly the page is moving to and point out that they should update bookmarks if necessary.

CNAME Redirects #

CNAME redirects are not true redirects but involve using a CNAME (Canonical Name) DNS record to alias one domain or subdomain to another. When a CNAME record is configured, DNS queries for the source domain (e.g., example.com) resolve to the target domain (e.g., new.example.com), directing users to the target server.

Preserving Paths #

While CNAMEs simplify DNS management, they do not handle HTTP-level redirects (e.g., preserving paths or using status codes). For true redirection (e.g., example.com/page to new.example.com/page), a server-side redirect or HTTP configuration is needed in conjunction with the CNAME.

Common Mistakes #

TLS Certificates #

If you change your domain name, you should continue to pay for the TLS certificates for the old domain for the time during which the redirects from the old domain to the new one are to continue. Otherwise, visitors to the https version of the old domain cannot be redirected.

Redirect chains #

Redirect chains occur when a series of redirects link multiple URLs before reaching the final destination (e.g., URL1 → URL2 → URL3). They negatively impact page load speed, degrade user experience, and may lead to penalties in search engines.

To avoid them, regularly audit your redirects, update links to point directly to the final URL, and consolidate unnecessary intermediary redirects into a single, direct redirect (e.g., URL1 → URL3). Always update links to the latest redirect target.

Redirect loops #

Redirect loops happen when a series of redirects unintentionally create a cycle, causing the browser to endlessly request pages (e.g., URL1 → URL2 → URL1). This results in errors like “Too many redirects” and prevents users from accessing the content, which negatively impacts the user experience.

To avoid them, carefully test and review redirect rules, ensure conditions are logically structured, and avoid setting redirects that point back to themselves or create circular dependencies. Use tools like browser developer tools or redirect testing software (like REDbot) to identify and fix loops.


Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

License: How to redirect users on the Web? by Jonas Jared Jacek is licensed under CC BY-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/instructions/how-to-redirect-users-on-the-web">How to redirect users on the Web?</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>

For more information see the DITig legal page.


“Learning from conventions will make your site better.”

Jeffrey Veen, American designer and design strategistThe Art & Science of Web Design, - IT quotes