A redirect tells browsers and search engines that an address has moved. Done well, visitors never notice and search engines pass the old page's standing to the new one. Done badly, you get broken bookmarks, pages that drop out of search, or a browser complaining about too many redirects.
301 or 302?
- 301, permanent. The old address is retired. Search engines replace it with the new one in their results, and browsers remember the move.
- 302, temporary. The old address will be back. Search engines keep the old one listed, and browsers ask again each time.
Use 301 for a renamed page, a changed site structure, or a move to a new domain. Use 302 for something short-lived: a maintenance notice, a seasonal page, a test. Using 302 for a permanent move is the classic mistake; the old address stays in search results for months.
The easy way: cPanel's Redirects page
- In cPanel, open Redirects (in the Domains section).
- Choose Permanent (301) or Temporary (302).
- Pick the domain and type the old path, for example
old-page.html. - Enter the full new address, including
https://. - Choose whether it applies with or without
www, or both, and add it.
cPanel writes the rule into .htaccess for you. The same page lists existing redirects and lets you remove them.
By hand in .htaccess
One page to another:
Redirect 301 /old-page.html https://yourdomain.com/new-page.html
A whole folder, keeping the rest of each address:
RedirectMatch 301 ^/blog/(.*)$ https://yourdomain.com/news/$1
An entire old domain to a new one, page for page:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]
Pick one form of your address
To a search engine, http://yourdomain.com, https://yourdomain.com, http://www.yourdomain.com and https://www.yourdomain.com are four different sites that happen to look alike. Choose one, and send the other three to it. To settle on HTTPS without www:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]
Writing it as a single rule matters. Two separate rules, one for HTTPS and one for www, send some visitors through two hops.
Order matters
Rules in .htaccess are read top to bottom. Put your redirects above the block that a content system such as WordPress adds, the one between the # BEGIN and # END comments. Rules placed below it are often never reached, because that block has already taken over the request.
Chains and loops
A chain is a redirect to an address that itself redirects. Each hop adds delay, and search engines give up following after a few. Whenever you add a redirect, check whether an older one already points at the address you are retiring, and update it to point straight at the final destination.
A loop is A sending to B while B sends back to A. The browser stops with "too many redirects". Loops usually come from two rules that each seem reasonable alone, or from a proxy in front of the site; the HTTPS guide covers the proxy case.
Test every redirect
curl -I https://yourdomain.com/old-page.html
The first line should show 301 and the location: line should show the final address, not an intermediate one. Add -L to make curl follow the whole chain and show each hop.
Test in a private browser window too. Browsers store 301s, so a wrong redirect you already fixed can keep replaying from your own browser's memory.
Do not redirect everything to the home page
When pages are removed it is tempting to point every old address at the front page. Visitors arrive expecting an article and get something unrelated, and search engines treat such a redirect as a "soft 404" and drop the old page anyway. Redirect each old page to its nearest real replacement. If there is none, let it return 404 or 410 and make your 404 page helpful.
After a restructure
- Update your own menus and internal links to the new addresses, so you do not depend on your own redirects.
- Update the sitemap to list only the new addresses.
- Keep the redirects in place for at least a year. Old links on other sites never get updated.
Common questions
Will a 301 cost me search ranking?
A like-for-like redirect passes the old page's standing to the new one. Expect a short wobble while search engines catch up, not a lasting loss. What does cost ranking is redirecting to a page about something else.
Can I redirect based on the visitor's country or device?
You can, but do it sparingly and never with a 301. Crawlers mostly visit from one country and one kind of device, and a permanent redirect would hide the rest of your site from them.
How many redirects can .htaccess hold?
Hundreds without trouble. Beyond that, use patterns such as RedirectMatch to cover whole groups with one line; the file is read on every request.