URL redirects: 301s, 302s, and htaccess basics

URL redirects send visitors from one URL to another. Used right, they preserve link equity during site reorganizations, fix broken bookmarks, and simplify URL structures. Used wrong, they cause infinite loops, lose SEO ranking, or break unrelated pages. This article covers the fundamentals.

301 vs. 302: the only distinction that matters

  • 301 (Permanent): the URL has moved and will not come back. Search engines transfer ranking from old to new. Browsers cache aggressively. Use this for almost everything.
  • 302 (Temporary): the URL is temporarily elsewhere. Search engines keep the old URL indexed. Browsers do not cache. Use this rarely — only for genuine temporary redirects.

Choose 301 unless you have a specific reason for 302. Many people default to 302 because some servers do, then wonder why their SEO didn't recover after a site reorg.

Method 1: cPanel Redirects tool

cPanel includes a redirects UI for simple cases:

  1. cPanel → Redirects (under "Domains").
  2. Pick redirect type (Permanent = 301, Temporary = 302).
  3. Pick the domain.
  4. Enter the path you want to redirect (leave blank for the entire domain).
  5. Enter the destination URL.
  6. Tick Wild Card Redirect if you want sub-paths to redirect to matching sub-paths on the destination.
  7. Click Add.

The cPanel tool writes the redirect to your .htaccess file under the hood. Useful for one-off rules; less useful for complex patterns.

Method 2: .htaccess directly

For control beyond the cPanel UI, edit your .htaccess file in public_html. Common patterns:

Redirect a single page

Redirect 301 /old-page.html https://yourdomain.com/new-page

Redirect a whole directory

RedirectMatch 301 ^/old-blog/(.*)$ https://yourdomain.com/new-blog/$1

Redirect non-www to www (or vice versa)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]

Pick one canonical form and stick with it. Splitting traffic across www and non-www dilutes SEO.

Redirect HTTP to HTTPS (force SSL)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

This belongs at the top of .htaccess. Detail in our force HTTPS article.

Strip trailing slashes

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]

Or add them, by inverting the condition. Pick one and be consistent.

Redirect old domain to new domain (after rebrand)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?olddomain.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]

Place this in .htaccess for the parked or addon domain.

Edit .htaccess in cPanel

  1. cPanel → File Manager.
  2. Navigate to public_html.
  3. Click Settings in the top-right and tick Show Hidden Files (dotfiles).
  4. Find .htaccess, right-click, choose Edit.

If .htaccess doesn't exist yet, create it: New File → .htaccess.

Test your redirects

Use curl -I from a terminal to see the actual HTTP response without browser caching:

$ curl -I https://yourdomain.com/old-page.html
HTTP/1.1 301 Moved Permanently
Location: https://yourdomain.com/new-page

Online tools like httpstatus.io let you trace whole redirect chains.

Common pitfalls

  • Infinite redirect loops. Two rules redirect back and forth. The browser shows "ERR_TOO_MANY_REDIRECTS." Comment out rules one at a time to find the conflict.
  • Redirect chains. Old URL redirects to intermediate redirect to final URL. Each hop loses SEO weight. Always redirect directly to the final destination.
  • Case sensitivity. Redirect matches paths case-sensitively by default. Use RedirectMatch with (?i) for case-insensitive matching.
  • Forgetting the protocol. Redirect 301 /old https://yourdomain.com/new works; Redirect 301 /old /new creates a relative redirect that may not behave as expected with HTTPS.
  • 302 by default. If you write Redirect /old /new without a status code, you get 302. Always specify 301 explicitly.
  • Cache poisoning. 301 redirects are aggressively cached by browsers. If you set up a wrong 301, fix it then test in incognito or a private window. Existing users may see the broken redirect for hours.
  • redirects, .htaccess, 301, 302, cPanel
  • 0 Utenti hanno trovato utile questa risposta
Hai trovato utile questa risposta?

Articoli Correlati

Nameservers

The nameservers to use for our webhosting services are below: all1.dnsroundrobin.net...

Setting up Dynamic DNS in cPanel

cPanel includes a built-in Dynamic DNS feature that automatically keeps an A record pointed at a...

Setting up Cloudflare with cPanel: the right way

Cloudflare is a free CDN and DDoS-protection service that sits in front of your ipxcore cPanel...

Speeding up WordPress on cPanel hosting

A slow WordPress site costs you visitors, conversions, and search rankings — Google has...

How to migrate your website to ipxcore from another host

Migrating an existing website to ipxcore is a process we've helped thousands of customers...