A domain redirect is a technique used to automatically send visitors from one domain or URL to another. This is useful for website migrations, rebranding, SEO optimization, and maintaining user experience when changing domain names or URLs.
A 301 redirect permanently redirects one URL to another and passes nearly all SEO value to the new URL.
Use Cases:
Example (Apache .htaccess file):
Redirect 301 /old-page.html https://example.com/new-page.html
A 302 redirect temporarily directs users to a new URL without passing SEO value permanently.
Use Cases:
Example (Nginx configuration):
rewrite ^/old-page$ https://example.com/new-page temporary;
A meta refresh redirect is executed at the page level instead of the server level.
Use Cases:
Example (HTML meta tag):
<meta http-equiv="refresh" content="5; url=https://example.com/new-page">
(This redirects after 5 seconds.)
JavaScript-based redirects occur client-side and require JavaScript to be enabled in the browser.
Use Cases:
Example:
window.location.href = "https://example.com/new-page";
Edit the .htaccess file in the root directory:
RewriteEngine On
RewriteRule ^old-page$ /new-page [R=301,L]
Edit the Nginx configuration file:
server {
listen 80;
server_name olddomain.com;
return 301 https://newdomain.com$request_uri;
}
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Domain redirects are essential for managing website migrations, consolidations, and improving user experience. Whether using 301, 302, or JavaScript-based redirects, implementing them correctly ensures seamless navigation for users and search engines.