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:
- cPanel → Redirects (under "Domains").
- Pick redirect type (Permanent = 301, Temporary = 302).
- Pick the domain.
- Enter the path you want to redirect (leave blank for the entire domain).
- Enter the destination URL.
- Tick Wild Card Redirect if you want sub-paths to redirect to matching sub-paths on the destination.
- 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
- cPanel → File Manager.
- Navigate to
public_html. - Click Settings in the top-right and tick Show Hidden Files (dotfiles).
- 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.
Redirectmatches paths case-sensitively by default. UseRedirectMatchwith(?i)for case-insensitive matching. - Forgetting the protocol.
Redirect 301 /old https://yourdomain.com/newworks;Redirect 301 /old /newcreates a relative redirect that may not behave as expected with HTTPS. - 302 by default. If you write
Redirect /old /newwithout 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.