If you’re a website owner or administrator, you probably know how important it is to maintain a smooth and seamless user experience on your site. However, there are times when you need to make changes to your website’s structure, reorganize content, or even change domain names. When these changes occur, it’s crucial to ensure that your visitors are seamlessly redirected to the new locations, and this is where 301 redirects come into play.
A 301 redirect instructs web browsers and search engines to permanently redirect users from one URL to another. Whether you’re moving a page, changing your website’s structure, or migrating to a new domain, using a 301 permanent redirect is essential to preserve your website’s SEO ranking, maintain user trust, and ensure a smooth transition for your audience.
Don’t have time to read our article on how to set up a 301 redirect? Watch our walkthrough video.
When would it be necessary to 301 redirect?
301 redirects are a crucial tool for maintaining a website’s user experience, SEO, and overall functionality. Here are some common reasons why website owners use 301 redirects:
- Changing URL Structure:
When you reorganize the structure of your website, such as renaming folders or pages, you’ll need 301 redirects to ensure that visitors can still find the content they’re looking for. Without redirects, they may encounter 404 errors.
- Migrating to a New Domain:
If you’re changing your domain name or moving your website to a new domain, 301 redirects are essential to seamlessly transfer your old website’s traffic to the new one. This helps maintain your SEO rankings and ensures visitors find your new website.
- Eliminating Outdated or Unused Pages:
When you delete or retire pages on your website, setting up 301 redirects can guide users to relevant or updated content instead of encountering 404 errors.
- Handling Trailing Slashes:
Consistency in URL structure is important for SEO. If your website URLs have inconsistent trailing slashes (e.g., “example.com/page” vs. “example.com/page/”), 301 redirects can be used to enforce a preferred URL format.
- Protocol Change:
If you’re switching from HTTP to HTTPS for improved security, you should set up 301 redirects to ensure that visitors and search engines access the secure version of your site.
- Managing Affiliate or Marketing Campaigns:
If you’re running marketing campaigns with unique tracking URLs or affiliate links, 301 redirects can be used to redirect these links to specific landing pages or offers.
- Fixing Canonicalization Issues:
To resolve issues related to duplicate content caused by multiple versions of URLs (e.g., with or without “www”), 301 redirects can be employed to specify the canonical version of the URL.
Experience the Power of a Dedicated Server
Know you will always be able to reach your customers when you need to with reliable and secure Dedicated Hosting. Get industry-leading hardware at an affordable dedicated server price.
DDoS Protection
Free Backup Storage
cPanel or Control Web Panel
Managed Server
Unmetered Bandwidth
Dedicated Server Hosting
Creating 301 Redirects: .htaccess vs. cPanel
When it comes to setting up 301 redirects on your website, you have two primary methods to choose from: editing your .htaccess file directly or using cPanel’s built-in redirection tools.
Editing .htaccess Directly:
Editing your .htaccess file directly provides you with full control over your redirects. You can implement complex rules and handle specific cases precisely. It operates at the server level, which can be more efficient, and it doesn’t rely on a control panel or third-party tools. However, it requires technical knowledge, and mistakes in the .htaccess file can lead to site errors or downtime.
Using cPanel:
cPanel offers a user-friendly interface for managing redirects, making it accessible even to those with limited technical expertise. It’s quick for simple redirects and provides visual feedback to help you understand the rules you’re setting up. However, it may lack the flexibility needed for complex redirect scenarios, and its availability depends on your hosting provider.
Choosing between these methods depends on your specific needs and technical comfort level. Use .htaccess for complex requirements and precise control, especially if you’re experienced with server configurations. Opt for cPanel if you prefer an easy, visual solution for basic redirects, or if you’re a beginner. In many cases, having a basic understanding of both methods can be beneficial for various redirect scenarios. Regardless of your choice, setting up 301 redirects is crucial for maintaining your website’s SEO ranking and ensuring a smooth user experience during changes and migrations.
Set Up 301 Redirect via .htaccess file
On a Linux server you would use your .htaccess file to implement a 301 redirect for your pages. We’ll now show you how to edit the .htaccess file, then go over the different redirect options.
- Login to your cPanel.
- Under Files, click on File Manager.

- Ensure that Show Hidden Files is selected by clicking Settings on the top right corner of the File Manager.

- Select the Document Root for: option, and choose your domain from the drop-down.
- Right-click on the .htaccess file and select Edit.

- If your .htaccess file is still not found after the previous steps, click on New File at the top-left, name the file .htaccess, and set the directory for the file to be created to /public_html/ or the document root of your site.
- You might have a text editor encoding dialog box pop-up, you can simply click on Edit to proceed.

Redirect files
To redirect individual files, like example.com/oldfile.htm to newfile.htm you can use a 301 redirect like this:
Redirect 301 /oldfile.htm /newfile.htm
To redirect one specific file to another domain such as example.com/oldfile.htm to example.net/newfile.htm:
Redirect 301 /oldfile.htm https://example.net/newfile.htm
.htaccess redirect to another domain
If you had an old domain such as example.com and you decided to use example.net for a website, you could setup a 301 redirect for the entire domain, so that old links to example.com carry over.
Sample of code from example.com domain’s .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example./$1 [L,R=301,NC]
Force www. on domain
A search engine such as Google interprets example.com and www.example.com as essentially two separate websites. It is recommended that users pick one version they’d like search engines to display. By using a 301 redirect, users can specify which domain name is displayed on their site.
If you have a number of links on the web where people are linking to your site as example.com, but you would prefer your visitors end up at www.example.com instead, you can force this version of your domain with these rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
Force non-www. on domain
If you have a lot of links on the web where people are linking to your site as www.example.com, but you would prefer your visitors end up at example.com instead, you can force this version of your domain with these rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]
Redirect files by extension
To re-direct all of one type of file to another, such as example.com/file.php to example.com/file.htm
RewriteEngine On
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]
You should now know how to properly setup 301 permanent redirects on your website to help ensure that search engines and visitors coming to your site from older links can still get to your new content.
Redirect vs. RedirectMatch
Up to this point, we have talked about the Redirect directive as a powerful tool for creating 301 redirects in your .htaccess file. However, it’s important to be aware that there is another directive available – RedirectMatch. These two directives serve distinct purposes and offer different levels of control when it comes to managing your website’s redirects. In this section, we will delve into the differences between Redirect and RedirectMatch to help you choose the right one for your specific redirect needs.
Redirect Directive
The Redirect directive is a simple and straightforward way to create 301 redirects. It’s primarily used for redirecting entire directories or individual URLs. Here’s a breakdown of its characteristics:
- Usage: The Redirect directive is ideal when you want to redirect one URL to another with a one-to-one mapping, such as redirecting an old page to a new page.
- Pattern Matching: It performs exact matches, meaning the source URL must precisely match the pattern specified. There’s no support for regular expressions, making it less flexible for complex redirect scenarios.
Example:
Redirect 301 /old-page.html /new-page.html
RedirectMatch Directive
The RedirectMatch directive offers more advanced control over your redirects, as it allows the use of regular expressions to define redirect patterns. Here are its key characteristics:
- Usage: RedirectMatch is suitable for scenarios where you need more flexibility in defining source URLs to redirect. It’s particularly useful when dealing with dynamic URLs or patterns of URLs.
- Pattern Matching: It supports regular expressions, enabling you to match a range of URLs that follow a specific pattern. This flexibility allows for more complex and dynamic redirects.
Example:
RedirectMatch 301 /category/(.*) /products/$1
Set Up 301 Redirect in cPanel
For users that host their sites on cPanel-based hosts, it is possible to set up redirects via the cPanel interface. This tool automatically adds the necessary code to the .htaccess file for the redirect to function properly.
- Login to cPanel.
- Click the Redirects button in the Domains section.

- You will then be on the Add Redirect page. Click the drop-down box for Type and choose either a Permanent (301) or Temporary (302) redirect.

- Click the next drop-down box and choose the domain you want to redirect.

- For the slash ‘/’ field, enter any folder names (if necessary).
- Enter the address you want to redirect to in the Redirects to section.

- Choose if you want to “Only redirect with www.” “Redirect with or without www.” or “Do Not Redirect www.“
- Check the box if you want to create a Wild Card Redirect. This will add the the file/folder name after the url when it redirects. For instance, example.com/test.php would redirect to example2.com/test.php.
- Click Add when finished.

The Common Typo: 310 Redirect vs. 301 Redirect
It’s not uncommon for users to inadvertently type “310 redirect” when they actually mean “301 redirect.” This might be due to a simple typographical error or a mix-up with numbers. While there is no HTTP status code officially designated as “310,” it’s essential to clarify this common typo to avoid confusion.
Congratulations, now you know how to create a redirect in your cPanel! Did you know? If you have a WordPress site, you can also create a 301 redirect directly in your dashboard.