Redirects send visitors and search engines from one URL to another. Setting them up correctly is essential for SEO, domain migrations, and enforcing HTTPS.
301 vs 302 Redirects
| Feature | 301 (Permanent) | 302 (Temporary) | |---|---|---| | Meaning | Page has permanently moved | Page is temporarily moved | | SEO | Transfers link equity to new URL | Does not transfer link equity | | Browser caching | Browsers cache aggressively | Not cached | | Use when | Domain change, URL restructure, HTTP to HTTPS | A/B testing, maintenance, seasonal pages |
Rule of thumb: Use 301 unless you specifically plan to bring the old URL back.
Method 1: cPanel Redirects Tool
The easiest method for basic redirects.
- Log in to cPanel
- Go to Domains > Redirects
- Configure:
- Type: Permanent (301) or Temporary (302)
- Domain: Select the domain from the dropdown
- Path: Enter the path to redirect from (e.g.,
/old-page) - Redirects to: Enter the full destination URL (e.g.,
https://yourdomain.com/new-page) - www redirection: Choose how to handle www vs non-www
- Click Add
Method 2: .htaccess Rules
For more control, edit the .htaccess file in your website root directory.
Redirect a Single Page
Redirect 301 /old-page https://yourdomain.com/new-page
Redirect 301 /blog/old-post https://yourdomain.com/blog/new-post
Redirect an Entire Directory
RedirectMatch 301 ^/old-directory/(.*)$ https://yourdomain.com/new-directory/$1
Redirect an Entire Domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?olddomain.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
Common Redirect Patterns
WWW to Non-WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
Non-WWW to WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Combined: HTTP to HTTPS + Non-WWW to WWW
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
Combined: HTTP to HTTPS + WWW to Non-WWW
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
Correct .htaccess Placement
When using WordPress, place your redirect rules before the WordPress rewrite block:
# Your redirects go HERE, above WordPress block
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Testing Your Redirects
Using curl
curl -I https://yourdomain.com/old-page
Look for the HTTP/1.1 301 Moved Permanently status and the Location: header showing the destination.
Using a Browser
- Open your browser's developer tools (F12)
- Go to the Network tab
- Visit the old URL
- Check the first request for a 301/302 status code
Online Tools
- httpstatus.io — check redirect chains
- redirect-checker.org — verify redirect type
Troubleshooting
- Redirect loop (ERR_TOO_MANY_REDIRECTS): Your rules are creating a circular redirect. Ensure conditions exclude the target URL. Clear browser cache between tests.
- 500 Internal Server Error: Syntax error in .htaccess. Check for typos, missing RewriteEngine On, or unsupported directives.
- Redirect not working: Clear browser cache (browsers aggressively cache 301s). Test in incognito mode.
- WordPress redirects not working: Make sure rules are placed before the WordPress block in .htaccess.
- Old redirect stuck: 301 redirects are cached by browsers. Clear cache or test in a new incognito window.