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

  1. Sign in to cPanel.
  2. Open Domains.
  3. Select Redirects.
  4. Choose Permanent (301) or Temporary (302).
  5. Select the source domain.
  6. Enter a path if only one page should redirect.
  7. Enter the complete destination URL.
  8. Choose how www should be handled.
  9. Add the redirect.
  10. Test it in a private browser window.

Create a redirect in DirectAdmin

  1. Sign in to DirectAdmin.
  2. Open Account Manager.
  3. Select Site Redirects.
  4. Choose the source path.
  5. Enter the complete destination URL.
  6. Select the redirect type.
  7. 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:

  1. Download a backup copy.
  2. Place a specific redirect before general WordPress rules.
  3. Do not remove panel- or application-generated lines.
  4. Make one change at a time.
  5. 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
  • www and non-www rules
  • WordPress site-address settings
  • Cloudflare redirect rules
  • Application-level redirects
  • Both the source and destination .htaccess files

Do not force HTTPS until the destination has a valid certificate. See How to force my website to use HTTPS.

Did this answer it?