How to redirect a domain or page
Choose the redirect type
| Type | Use |
|---|---|
| 301 permanent | The old address has moved permanently |
| 302 temporary | The redirect is temporary or still being tested |
Browsers and search engines may cache permanent redirects. Test with a temporary redirect first if you are unsure.
Create a redirect in cPanel
- Sign in to cPanel.
- Open Domains.
- Select Redirects.
- Choose Permanent (301) or Temporary (302).
- Select the source domain.
- Enter a path if only one page should redirect.
- Enter the complete destination URL.
- Choose how
wwwshould be handled. - Add the redirect.
- Test it in a private browser window.
Create a redirect in DirectAdmin
- Sign in to DirectAdmin.
- Open Account Manager.
- Select Site Redirects.
- Choose the source path.
- Enter the complete destination URL.
- Select the redirect type.
- Save and test it.
Redirect a whole domain with .htaccess
Both Apache (cPanel) and OpenLiteSpeed (most DirectAdmin servers) read rewrite rules from .htaccess.
Add this to the old domain's .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.co\.za$ [NC]
RewriteRule ^(.*)$ https://new-domain.co.za/$1 [R=301,L]
Replace both example domains. This keeps the path, so old-domain.co.za/contact goes to new-domain.co.za/contact.
Redirect one page with .htaccess
RewriteEngine On
RewriteRule ^old-page/?$ https://example.co.za/new-page [R=301,L]
Do not include the leading slash in the RewriteRule pattern.
Find the correct .htaccess file
- cPanel main domain:
/home/USERNAME/public_html/.htaccess - DirectAdmin:
/home/USERNAME/domains/DOMAIN/public_html/.htaccess
Addon domains use the document root selected when the domain was created.
The file is hidden because its name begins with a dot. See How to upload and manage files with File Manager for how to show hidden files.
Protect existing application rules
Before editing .htaccess:
- Download a backup copy.
- Place a specific redirect before general WordPress rules.
- Do not remove panel- or application-generated lines.
- Make one change at a time.
- Restore the backup if the website returns a 500 error.
WordPress-generated rules sit between # BEGIN WordPress and # END WordPress. Place custom redirects outside that block.
Avoid redirect loops
A loop occurs when one rule redirects to another rule that sends the visitor back.
Check:
- HTTP-to-HTTPS rules
wwwand non-wwwrules- WordPress site-address settings
- Cloudflare redirect rules
- Application-level redirects
- Both the source and destination
.htaccessfiles
Do not force HTTPS until the destination has a valid certificate. See How to force my website to use HTTPS.
Did this answer it?