SEO – Redirection
A redirect sends the visitor (and the search engine bot) from one URL to another URL automatically. When you move a page, change the URL, or delete a page, a redirect makes sure that people and the ranking signals of the old page reach the new one.
When do we need a redirect?
- You changed the URL of a page or the structure of the site.
- You moved to a new domain.
- You moved from
httptohttps. - You want only one version of the site, with or without
www. - You deleted a page and there is a closely related page to send the visitors.
Types of redirects
| Code | Name | Meaning | Use it for |
|---|---|---|---|
| 301 | Moved permanently | The page moved for ever | Changed URLs, domain move, http to https |
| 302 | Found (temporary) | The move is temporary | A short test or a temporary offer page |
| 307 | Temporary redirect | Temporary, and keeps the request method | Temporary redirect for forms and APIs |
| 308 | Permanent redirect | Permanent, and keeps the request method | Permanent redirect for forms and APIs |
For normal pages, a 301 is the one you need most of the time. Google treats a 301 as a strong signal that the new URL is the one to keep, and ranking signals move to it.
Redirect with .htaccess (Apache)
# one page
Redirect 301 /old-page/ https://example.com/new-page/
# http to https for the whole site
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# non-www to www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Redirect with Nginx
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
Redirect with PHP
<?php
header("Location: https://example.com/new-page/", true, 301);
exit;
Call header() before any output is sent, and always write exit after it.
Redirect in WordPress
You can use a redirect plugin (for example Redirection, or the redirect manager of Yoast SEO Premium or Rank Math). Type the old URL and the new URL, and choose 301. The plugin keeps a list, so it is easy to manage.
Mistakes to avoid
- Redirect chains: A goes to B, then B goes to C. Each step is slow. Redirect A directly to C.
- Redirect loops: A goes to B and B goes back to A. The page never opens.
- Redirecting everything to the home page. If the new page is not related, Google may treat it as a soft 404. Redirect to the closest matching page, or let it be a real 404 or 410.
- Using JavaScript or meta refresh redirects when a server redirect is possible. Server side redirects are clearer for search engines.
- Forgetting to update internal links. Link directly to the new URL.
Check a redirect
curl -I http://example.com/old-page/
The result should show HTTP/1.1 301 Moved Permanently and a Location: line with the new address. You can also use online redirect checker tools.
| Exercises & Assignments |
|---|
| Redirect old URLs to new URLs with .htaccess |
| Interview Questions & Answers |
|---|
| What is the difference between a 301 and a 302 redirect? |
| What is a 404 error and a soft 404? |
| How do you do a website migration without losing SEO? |