Use a 301 redirect any time you need to send users to a different page and want to keep your traffic and SEO intact. Some of the most common scenarios for 301 redirects are when you’re consolidating duplicate pages into one main page and when you’re migrating from HTTP to HTTPS. A permanent redirect will notify the visitor’s browser to update any bookmarks that are linked to the page that is being redirected (also called 301 redirect). Temporary redirects will not update the visitor’s bookmarks (also called 302 redirect).
How to redirect a domain or web page using hosting cPanel #
The easy way of setting a redirection is to use your cPanel option where you just click the desired option, choose a domain or page (in case of multiple domains) and save your settings. Then the system generates .htaccess file in the root of your website with some rules that give the instructions to visitors’ browser about redirection to another URL.
How to redirect a domain or web files using .htaccess file #
If, for some reason, you don’t have the option of using the cPanel to set up the redirection you can also do that manually by creating .htaccess file (or editing the existing one if your website already uses it).
Redirects only work if the rewrite engine (a feature in Apache that allows redirects) is turned on. Look for the following code near the top of the file. Or add it to your .htaccess file if it’s not already there:
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
Redirecting a Single URL #
Add this 301 redirect to your .htaccess file if you need to redirect one page to another.
RewriteEngine on
RewriteRule ^old-page/?$ https://www.yourdomain.com/new-page/ [R=301,L]
Redirecting a Single Folder #
Use this rule when you need to redirect whole sections of your site (like redirecting “/blog” to “/news”).
RewriteEngine on
RewriteRule ^blog/(.*)$ /news/$1 [R=301,L]
Redirecting WWW to Non-WWW URLs #
Redirecting www to non-www URLs helps prevent duplicate content issues by ensuring search engines don’t see www and non-www versions as separate pages with identical content.
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*) https://yourdomain.com/$1 [R=301, L]
Redirecting a Website to a New Domain #
Use this .htaccess rule to redirect your entire website to another domain.
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
Redirecting HTTP to HTTPS #
HTTPS (the encrypted version of HTTP) is a ranking factor, and forcing HTTP to HTTPS helps secure your site and improve your SEO.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
Your .htaccess file should be placed in the root of your website via FTP. Please note that in the root of your website you might already have an .htaccess file that may or may not contain additional code. Always make a backup copy of it before making any changes because improper use of this file might cause your website to crash or show some errors.