How to Set Up 301 Redirects in cPanel and .htaccess
In this article9 sections
You moved a page, renamed a product or merged two blog posts, and now the old address returns a 404 Not Found. Visitors who bookmarked it leave, and search engines lose the ranking the old page earned. A permanent redirect fixes both problems: it sends visitors and search engines to the new address, and it passes the ranking along. On a cPanel account, you can create redirects in the Redirects tool, or write them yourself in .htaccess. This guide covers both, the difference between a 301 and a 302, and how to test each redirect.
SiteHarbour’s cPanel plans run Apache or LiteSpeed, and both read the same .htaccess rules, so the examples below work on any plan.
301 or 302: choose the right status code
A 301 is a permanent redirect. It tells browsers and search engines that the new address is the real one, so the old address’s ranking moves to it. A 302 is a temporary redirect, which tells them to keep the old address in their index. For a page you moved for good, always use a 301. Use a 302 only for a short test, such as a page under maintenance, and remove it afterwards.
Step 1: Use the Redirects tool for a few addresses
In cPanel, open Redirects under Domains. Choose the domain, enter the old path in the first box, and the full new address in the second. Select Permanent (301) in the type list, then Add. Expected: the redirect appears in the list. Test it right away, as described in Step 4.
The Redirects tool works well for a handful of addresses. For a long list, write the rules yourself, as in Step 2.
Step 2: Write the rules in .htaccess
For a single page, add one line to .htaccess in the site’s root folder, above the WordPress block if the site runs WordPress:
Redirect 301 /old-page/ https://example.com/new-page/
For a folder that moved, redirect the whole folder and keep the rest of the path:
RedirectMatch 301 ^/old-folder/(.*)$ https://example.com/new-folder/$1
The first version matches one address. The second matches every address that starts with the old folder, and passes the rest of the path through. Use RedirectMatch only when the pattern is exact, because a loose pattern can redirect pages you did not mean to move.
Step 3: Avoid loops and chains
A redirect loop happens when page A sends to B and B sends back to A. The browser stops with a “too many redirects” error. A chain happens when A sends to B, and B sends to C. Search engines follow a chain but lose some ranking on each step. Point every old address straight at its final destination, and check the list after each change, because a rule added later can create a loop with an earlier one.
Also check that the new address does not redirect again, such as from HTTP to HTTPS, which can happen when the rule uses the wrong protocol. Always write the new address in full, with HTTPS.
Step 4: Test each redirect
From a terminal, request the old address and read the response headers without following the redirect:
curl -sI https://example.com/old-page/ | head -n 3
Expected: a status line of HTTP/2 301, and a location line that gives the new address in full. If the status is 404, the rule did not match, so check the path for a trailing slash and for capital letters, which matter. If the status is 302, the rule uses the wrong type.
For a chain check, follow the redirects to the end:
curl -sIL https://example.com/old-page/ | grep -i "^HTTP\|^location"
Expected: one redirect, then a 200 response. Two or more redirects mean a chain, and the rule should point at the final address.
Step 5: Update the internal links
A redirect works, but every internal link that still points at the old address makes the browser redirect again. Search the site for the old address and update the links to the new one. The redirect is then a safety net for outside links, which is what it is for.
Step 6: Keep the list in one place
Record each redirect in a simple list with the old address, the new address and the date. Without the list, a page moved again later can end up in a chain, and nobody knows why. Review the list once a year, and remove redirects for pages that have had no traffic for a long time, after you check the logs.
Common mistakes
- Using a 302 for a permanent move. The ranking does not pass to the new address.
- Redirecting everything to the home page. Search engines treat that as a soft error, and visitors lose the page they wanted.
- Forgetting the protocol. A new address written as HTTP redirects again to HTTPS.
- Editing
.htaccesswith a typo. A broken file returns a 500 error on every page. Keep a copy before each change. - Creating chains over time. Point each old address at the final address.
Frequently asked questions
How long does a 301 take to take effect?
Browsers and search engines follow it on the next visit. Search engines update their index over days or weeks, so the change does not show at once.
Do I need to remove the old page?
No. The redirect replaces it, so you can delete the old page. Keep the redirect in place for a long time, because outside links to the old address may still exist.
Can I redirect one domain to another?
Yes, with a rule that matches every path on the old domain and sends it to the new one, or with the domain’s redirect option in cPanel.
Why does a redirect work for me but not for a visitor?
The browser may have cached an old redirect. Test with curl, which does not cache, and clear the browser cache for your own check.
A permanent redirect keeps visitors and search ranking when a page moves. Use a 301, point each old address straight at the final address, write the new address in full with HTTPS, and test each rule with curl. Keep a list of the redirects, and update the internal links so the redirects are only needed for outside links. For the other half of a clean site move, read how to move a WordPress site to a new host without downtime.