.htaccess & URL Rewrites

Links and Redirects: Comprehensive Guide to 301, 302, 404, 410, and More

By the Domain India teamPublished 9 min read
Knowledge base article
Contents (10 sections)

Every time you rename a page, delete a product or move to a new domain, your server has to tell browsers and search engines what happened. It does that with an HTTP status code: 301 or 308 for a permanent move, 302 or 307 for a temporary one, 404 for "not found", 410 for "gone for good" and 503 for "down for maintenance". This guide explains when to use each one and gives working rules for Apache hosting, including cPanel's own tools.

Key takeaways

Use a 301 when a page has moved for good, a 302 only when it will come back, a 410 when you have deleted a page on purpose with no replacement, and a 503 with a Retry-After header during maintenance. Redirect each old URL in one hop to the most relevant new page, not to the home page. On cPanel, add redirects under Domains › Redirects and custom error pages under Advanced › Error Pages, or write the rules in .htaccess.

1. The status codes that matter

CodeMeaningUse it whenWhat search engines do
301 Moved PermanentlyThe page has a new permanent addressYou renamed a URL, moved to HTTPS or changed domainMove the old URL's ranking signals to the new one
308 Permanent RedirectLike 301, but the request method must not changePermanent moves of forms or API endpoints that receive POSTSame as 301
302 FoundThe page is temporarily somewhere elseA short promotion, A/B test or temporary moveUsually keep the old URL indexed
307 Temporary RedirectLike 302, but the request method must not changeTemporary moves that must keep POST as POSTSame as 302
404 Not FoundNothing exists at this addressAny URL that never existed or has no replacementDrop the URL from the index after repeated checks
410 GoneThe page existed and was removed on purposeDeleted products, expired offers, removed spam pagesDrop the URL, often a little faster than for a 404
503 Service UnavailableThe site is temporarily downPlanned maintenanceCome back later instead of dropping pages

Older guides say a 302 "passes no SEO value". That is no longer accurate: Google treats both as redirects. The difference is which URL it keeps in the index, so use 301 or 308 for anything permanent, and do not leave a 302 in place for months.

2. Redirect rules for .htaccess

Our shared hosting runs the Apache web server, so .htaccess rules work. mod_rewrite is enabled on cPanel, DirectAdmin and Webuzo, and on cPanel and DirectAdmin we have also confirmed the modules behind Redirect and Header. Put the file in the site's document root (usually public_html).

A single page

apache
# Permanent move of one page
Redirect 301 /old-page https://www.example.com/new-page

# Temporary move
Redirect 302 /sale https://www.example.com/diwali-offer

Redirect also matches everything below the path, so Redirect 301 /blog https://www.example.com/articles sends /blog/post-1 to /articles/post-1.

Patterns with mod_rewrite

For more control, such as moving a whole folder or changing file extensions, use mod_rewrite, which is available on all our shared servers:

apache
RewriteEngine On

# Move every page in /shop/ to /store/, keeping the rest of the path
RewriteRule ^shop/(.*)$ /store/$1 [R=301,L]

# Old .html pages to extensionless URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ /$1 [R=301,L]

Test each pattern on a few real URLs before you rely on it. For the full HTTPS and www rules, see how to redirect non-www to www, and for rewrite basics see the mod_rewrite guide.

Do not mix Redirect and RewriteRule for the same URLs

Redirect (mod_alias) and RewriteRule (mod_rewrite) are processed separately, so combining them for overlapping URLs can produce two redirects or a loop. Pick one style per site; if you already use RewriteRule for WordPress or HTTPS, write your redirects with it too.

3. Redirects in cPanel without editing files

  1. Open Redirects.
    Log in to cPanel and open Domains › Redirects.
  2. Choose the type.
    Pick Permanent (301) or Temporary (302).
  3. Enter the addresses.
    Select the domain, type the old path (for example /old-page) and the full new URL.
  4. Choose the www option
    that matches your site, then click Add.
  5. Test it
    with a cache-busting query string, as explained in section 7.
cPanel Redirects page with the Add Redirect form: type Permanent (301), domain, path, Redirects to, www. redirection options and Wild Card Redirect
Add a 301 or 302 in cPanel without editing .htaccess.

cPanel writes these rules into your .htaccess file, so you will see them there too. In DirectAdmin and Webuzo, write the rules in .htaccess as shown above; if you cannot find a redirect tool in the panel, ask support.

4. 404 and custom error pages

A helpful 404 page keeps visitors on your site. It should say clearly that the page was not found, offer a search box or links to your main sections, and still return the 404 status code.

apache
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

Use a local path such as /404.html. If you give a full URL (https://...), Apache sends a redirect instead of a 404, and search engines see a "soft 404". Also avoid redirecting every missing page to the home page; Google treats that as a soft 404 too.

In cPanel, Advanced › Error Pages lets you edit the page for each code without writing the rule yourself. WordPress uses its theme's 404 template instead.

5. 410 Gone for pages you removed on purpose

apache
# One page
Redirect gone /discontinued-product

# A whole folder of removed pages
RewriteEngine On
RewriteRule ^old-catalogue/ - [G]

Use 410 only when there is no sensible replacement. If a close match exists, a 301 to that page is better for visitors and keeps the old page's links working.

6. 503 for planned maintenance

A 503 tells search engines the site is down for a short time, so they come back later instead of removing your pages. Put your own IP address in the exception so you can still work on the site:

apache
ErrorDocument 503 /maintenance.html
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^203\.0\.113\.25$
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^ - [R=503,L]
Header always set Retry-After "3600"

Replace 203.0.113.25 with your own public IP address. Note the - in the rule: with a status outside the 3xx range, Apache ignores any target URL, and ErrorDocument supplies the page instead. Remove the block as soon as maintenance ends; a 503 left for days can still cost you rankings.

7. Best practices and testing

Do
  • Redirect each old URL straight to its final address in one hop
  • Send each old page to the most relevant new page
  • Update internal links and your sitemap to the new URLs
  • Keep permanent redirects in place for at least a year
Avoid
  • Redirect chains such as http to www to https to the new page
  • Sending every removed page to the home page
  • Meta refresh or JavaScript redirects when a server redirect is possible
  • Leaving a 302 in place for a permanent move

Check the real status code with curl:

bash
curl -sI "https://www.example.com/old-page?t=1" | head -n 5
Why a new redirect seems not to work on cPanel

Our cPanel servers put an nginx cache in front of Apache that keeps normal pages and 301 and 302 responses for up to 120 minutes. A redirect you just added or removed can look unchanged for that long. Add ?t= and any value to the URL, as in the curl example, to see what Apache is really answering.

After a site move, watch the Pages report in Google Search Console for new 404 errors and add redirects where old URLs still get visits. For reading unexpected codes, see HTTP status codes in cPanel and DirectAdmin.

8. Where Domain India fits

All of this works on our shared hosting: cPanel includes the Redirects and Error Pages tools, and .htaccess with mod_rewrite works on cPanel, DirectAdmin and Webuzo. On Webuzo, test a Redirect or Header line before relying on it. Compare plans on cPanel hosting or DirectAdmin hosting.

What is the difference between a 301 and a 302 redirect?

A 301 says a page has moved permanently, so search engines index the new URL. A 302 says the move is temporary, so they usually keep the old URL in the index. Use 301 for any permanent change of address.

Should I use 404 or 410 for a deleted page?

Use 410 when you removed the page on purpose and it will not come back; search engines often drop it a little faster. Use 404 for addresses that never existed. If a close replacement page exists, a 301 to it is better than either.

Is it bad to redirect all missing pages to my home page?

Yes. Search engines treat those redirects as soft 404 errors, and visitors land on a page they did not ask for. Redirect each old URL to its closest match, or return a real 404 or 410.

Where do I add redirects in cPanel?

Open Domains › Redirects, choose Permanent (301) or Temporary (302), enter the old path and the new URL, and click Add. cPanel writes the rule into your .htaccess file.

Why does my redirect not show up straight away?

On our cPanel servers an nginx cache can keep normal pages and redirect responses for up to 120 minutes. Add ?t= and any value to the URL to see the live response from the server.

Ready to tidy up your links? Read how to redirect non-www to www, check Mastering .htaccess, or open a support ticket if a redirect loops.

Need hosting that handles redirects properly?

cPanel hosting includes Redirects, Error Pages and full .htaccess support for every site on your plan.

See cPanel plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
301, 302, 404, 410 and 503: Redirects Guide for Websites