A redirect from one address to another is more than a technical setting. It is a critical tool for protecting traffic, search rankings, and user experience. If a page has moved, changed its URL structure, or been removed entirely, a properly configured redirect helps visitors avoid a 404 error and helps search engines transfer link equity to the new address.
In this article, we will go through every major way to set up a redirect, from server-level configuration to client-side options, and we will separate the methods that are considered safe for SEO.
What Is a Redirect and Why Is It Needed?
A redirect is an automatic transfer from one web address to another. Think of it like moving to a new apartment but leaving a sign at your old address that says, “We’re here now.” Without that sign, anyone who shows up at the old address simply leaves without finding anything. On the web, that sign is called a redirect. It is needed when you change domains, rename pages, combine multiple sites, or remove old content and replace it with something similar.
The main goal is simple: do not leave the visitor staring at an error page. Help them get to the place they actually wanted to reach.
All Redirect Methods
There are many ways to send a user from one URL to another, from web server rules to client-side scripts.
Each method has its own strengths, limitations, and use cases. Below are the main ones.
All examples below will use our site as the reference:
- Need a redirect from https://poznayu.com/article-1/
- to https://poznayu.com/article-2/
Server-Side Redirects on Apache
The most common method for Apache-based sites is using the .htaccess file.
Inside it, you can define redirect rules with the Redirect directive or RewriteRule. For example, to redirect everything from an old domain to a new one, you would write: Redirect 301 / https://new-site.com/
Redirect 301 /article-1/ https://poznayu.com/article-2/
For more advanced rules, such as replacing part of a URL, you use the mod_rewrite module: first RewriteEngine On, then a rule such as RewriteRule ^old-page$ /new-page [R=301,L].
RewriteEngine On
RewriteRule ^article-1/?$ /article-2/ [R=301,L]
These settings work at the server level before the page is even generated, so they are the fastest option and preserve SEO value fully.
Poznayu.com editor’s pick.
Server-Side Redirects on Nginx
On Nginx servers, redirects are written in the configuration file, usually inside a server block.
For a permanent redirect of the entire site, the return 301 https://new-address$request_uri
; directive is used. To redirect a single page, you would write something like location /old-path { return 301 /new-path; }.
location /article-1/ {
return 301 https://poznayu.com/article-2/
;
}
Nginx also supports rewrite-based redirects as an alternative:
rewrite ^/article-1/?$ /article-2/ permanent;
Nginx handles these rules very efficiently, which is why this method is often chosen for high-traffic projects. The advantage is flexibility and the fact that you do not need to restart the server after every change — reloading the configuration is enough.
Redirects Through Programming Languages (PHP, Python, Node.js)
If you do not have access to server administration or need to make redirect decisions based on more complex logic such as sessions or database checks, you can handle redirects at the script level. In PHP, this is done with the header function: header(‘HTTP/1.1 301 Moved Permanently’); header(‘Location: https://new-address
‘); exit;.
This code is placed at the top of the file, for example article-1.php or index.php:
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://poznayu.com/article-2/
");
exit;
A more advanced version checks the URI and can be inserted into a shared template:
if ($_SERVER['REQUEST_URI'] == '/article-1/' || $_SERVER['REQUEST_URI'] == '/article-1') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://poznayu.com/article-2/
");
exit;
}
Python frameworks such as Django and Flask, and Node.js frameworks such as Express, also have their own ways of sending HTTP headers. This approach gives you maximum flexibility, but it requires the script to run first, which means the server must start the program before the redirect happens.
Example for Node.js (Express) — route example:
app.get('/article-1', (req, res) => {
res.redirect(301, '/article-2');
});
And Python (Flask) — route example:
@app.route('/article-1')
def redirect_article():
return redirect('https://poznayu.com/article-2/
', code=301)
And for Python (Django) — in urls.py:
from django.views.generic import RedirectView
urlpatterns = [
path('article-1/', RedirectView.as_view(url='/article-2/', permanent=True)),
]
This is a little slower than server-level configuration, but for most tasks the difference is negligible.
And finally, for ASP.NET, if that is what you use:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect article-1 to article-2" stopProcessing="true">
<match url="^article-1/?$" />
<action type="Redirect" url="/article-2/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
Redirects Through Client-Side Technologies (JavaScript and HTML)
Sometimes a redirect needs to happen in the browser. The simplest option is a meta tag in HTML: <meta http-equiv=”refresh” content=”0; url=https://new-address”>. It forces the page to refresh to the new URL. However, search engines treat this type of redirect less favorably than a server-side redirect and may not fully transfer link equity.
For example:
<meta http-equiv="refresh" content="0; url=https://poznayu.com/article-2/">
A better choice in this case is JavaScript:
<script> window.location.replace("https://poznayu.com/article-2/"); </script>
The same goes for a delayed redirect, for example, when you need to show a message first:
<script> setTimeout(function() { window.location.href = "https://poznayu.com/article-2/"; }, 0); </script>
A more flexible but still not SEO-recommended option is JavaScript: window.location.href = “https://new-address”;. These methods are used when you do not have access to the server, such as on static hosting or archived sites.
Redirects Through Content Management Systems (CMS)
Almost all popular CMS platforms have built-in tools for configuring redirects.
- In WordPress, this can be done with plugins such as Redirection or through the .htaccess file.
- Joomla has components for managing redirects.
- Drupal allows redirect configuration through the Path Redirect module.
The advantage here is convenience and a user-friendly interface that does not require coding. The downside is dependence on CMS performance: the redirect happens after the system loads, which is a little slower than a server-level method.
Redirects Through DNS
Sometimes you need to redirect an entire domain without involving the web server.
For this, DNS records such as CNAME are used to point one domain to another. However, CNAME does not redirect a path — it only covers the whole domain. For more specific routing, you can use an A record pointing to another IP address, but that still does not create an HTTP-level redirect.
DNS methods are useful when you need to switch hosting quickly, but they do not preserve SEO value for individual pages and they do not pass through URL parameters. For proper redirect handling that preserves rankings, you still need server-side configuration.
SEO-Friendly Redirect Methods
Not all redirects are equally useful for search optimization. Search engines evaluate the server response code and use it to decide whether to transfer link equity, how long to keep the old URL indexed, and how quickly to index the new one. That is why using the correct redirect status code is important.
301 (Moved Permanently) is the most important code for a page that has moved permanently. It tells search engines: “This page has moved to a new address for good, and all accumulated authority, including backlinks and rankings, should be passed to the new URL.” That is the code you use when changing domains, moving a site to a new CMS, or merging pages. It should always be used when the old address will no longer exist and the new one is its full replacement.
Example in .htaccess: Redirect 301 /old-page https://site.com/new-page. After that, Google and other search engines gradually replace the old URL with the new one in search results while transferring most of the value.
Redirect 301 /article-1/ https://poznayu.com/article-2/
302 (Found) / 307 (Temporary Redirect) are temporary redirects. They are used when the redirect is short-term, for example during maintenance, seasonal promotions, or testing a new version of a page. With a 302, the search engine keeps the old URL indexed, and the new one does not receive the full value. In modern specifications, 307 is recommended for temporary redirects because it clearly separates temporary handling from permanent redirection and does not let browsers override the request method.
Example: Redirect 302 /promo https://site.com/temp-page. It is important not to confuse 302 with 301, or you may accidentally flatten SEO performance for a long time.
Redirect 302 /article-1/ https://poznayu.com/article-2/
308 (Permanent Redirect) is the permanent counterpart to 307. It was introduced as a stricter version of 301, guaranteeing that the request method such as GET or POST stays unchanged. In most cases, 301 is enough for ordinary sites, but if you need to redirect POST requests while preserving the method, 308 is the better choice.
Example in Nginx: return 308 /new-address;. Search engines support 308 similarly to 301, but it is used less often.
location /article-1/ {
return 308 https://poznayu.com/article-2/
;
}
SEO Recommendation Comparison:
| Redirect Code | Type | Purpose | SEO Impact |
|---|---|---|---|
| 301 | Permanent | Full URL replacement, site move | Passes 90–99% of value, old address is removed from the index |
| 302 / 307 | Temporary | Temporary promotions, tests | Does not pass value, old URL stays indexed |
| 308 | Permanent | Same as 301, but preserves request method | Similar to 301 |
For SEO, it is critical not to use temporary redirects such as 302 or 307 for permanent moves. If you plan to close an old URL forever, always use 301 or 308. You also need to avoid redirect chains such as page → page2 → page3, because each extra hop slows loading and slightly weakens value transfer. Ideally, there should be only one redirect from the original URL to the final one.
In the end, the right redirect is a balance between technical implementation and user care. Server-side methods offer the best speed and SEO benefits, CMS plugins are convenient for everyday admins, and client-side scripts should be used only in exceptional cases. The key is to choose the redirect code deliberately and always check the result after setup.
Welcome to Poznayu.com!
My name is Alex, and I founded this project together with a team of like-minded professionals. At Poznayu.com, we create in-depth reviews, explore fascinating facts, and share well-researched, reliable knowledge that helps you navigate complex topics with confidence.
Our mission is simple: to explain complicated ideas in clear, accessible language. We believe that high-quality information should be available to everyone. Every article we publish is designed to provide practical value, actionable insights, and trustworthy analysis you can rely on.
Join our growing community of curious readers. Your feedback matters — share your thoughts in the comments, ask questions, and suggest topics you’d like us to cover next.





