How to Set Up Redirects and Rewrite Rules in cPanel

How to Set Up Redirects and Rewrite Rules in cPanel

How to Set Up Redirects and Rewrite Rules in cPanel

 

How to Set Up Redirects and Rewrite Rules in cPanel

A comprehensive guide to creating 301/302 redirects and rewriting URLs for better SEO and site management.

Why Redirects and Rewrite Rules Matter

Redirects and URL rewrites are essential tools for website owners and developers. Whether you’re moving pages, restructuring your site, or optimizing URLs for search engines, setting up proper redirects and rewrite rules can:

  • Preserve your search engine rankings
  • Avoid broken links and 404 errors
  • Improve user experience
  • Enable temporary or permanent URL changes

In this guide, you will learn how to create 301 (permanent) and 302 (temporary) redirects and how to use rewrite rules to manage URLs effectively using cPanel.

Understanding Redirect Types

  • 301 Redirect (Permanent): Tells browsers and search engines that a page has permanently moved to a new URL. SEO benefits are transferred.
  • 302 Redirect (Temporary): Indicates the move is temporary, so search engines keep the original URL indexed.
  • Rewrite Rules: Used to change how URLs appear without changing the underlying file structure, typically via .htaccess files.

Step 1: Creating Redirects in cPanel

Access the Redirects Tool

  1. Log in to your cPanel account.
  2. Scroll down to the Domains section.
  3. Click on Redirects.

Set Up a Redirect

  1. Choose Redirect Type: Select Permanent (301) or Temporary (302) from the dropdown.
  2. Select Domain: Choose the domain you want to redirect from the dropdown.
  3. Enter the Redirect Path: Specify the exact page or leave blank to redirect the entire domain.
  4. Destination URL: Enter the full URL where you want to send visitors (e.g., https://newdomain.com/page).
  5. Options:
    • Redirect with or without www: Choose whether to redirect both www and non-www versions.
    • Wild Card Redirect: Check this box if you want to redirect all files within a directory to the same files in the new location.
  6. Add Redirect: Click the Add button to save the redirect.

Step 2: Managing Redirects

  • View existing redirects on the same page.
  • Remove or edit redirects as needed to maintain proper site navigation.

Step 3: Using Rewrite Rules via .htaccess in cPanel

What is .htaccess?

The .htaccess file is a powerful configuration file used by Apache servers to control website behavior, including URL rewriting.

Access .htaccess File

  1. In cPanel, open File Manager.
  2. Navigate to the root directory (public_html or the relevant domain folder).
  3. Enable Show Hidden Files (dotfiles) from settings to see .htaccess.
  4. Edit the .htaccess file or create one if it doesn’t exist.

Example Rewrite Rules

Redirect non-www to www:

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

Rewrite URLs to remove .php extension:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Redirect HTTP to HTTPS:

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

Best Practices for Redirects and Rewrite Rules

  • Test Redirects: Use online tools to check if redirects are working properly.
  • Avoid Redirect Chains: Too many redirects can slow down your site and harm SEO.
  • Backup .htaccess: Always back up your .htaccess file before making changes.
  • Use Clear URLs: Rewrite rules should make URLs clean and user-friendly.

Frequently Asked Questions (FAQs)

How long does a 301 redirect take to update in search engines?
It can take days or weeks; 301 redirects inform search engines permanently but require crawling.
Can I set up redirects without affecting SEO?
Yes, if done correctly—301 redirects transfer SEO value; 302 should be used only temporarily.
What happens if I remove a redirect?
Visitors may see 404 errors unless the original page is restored or redirected elsewhere.

Need Assistance with Redirects?

If you host with Hiverift, their expert support can help you configure redirects and rewrite rules:

Conclusion

Redirects and rewrite rules are essential tools for website management and SEO optimization. Using cPanel’s Redirects tool and .htaccess editing, you can easily control your URL structure, preserve SEO rankings, and provide a better user experience.

Post Your Comment

Build Your Website with HiveRift

From professional business to enterprise, we’ve got you covered!

©2025, Hosting. All Rights Reserved by KhatuShyam Technologies

HiveRift
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.