How do I setup a 301 redirection?

  • September 13, 2017
  • 0 Comments

Sometimes we need to change the URL of pages, but it is a risky task, because if your pages are already indexed in search engines, you will lose not only visitors but also your SEO ranking. Your indexed URLs will start to disappear one by one, forcing you to start from scratch again

If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a 301 redirect. This is the best search engine and user-friendly way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.

You can do it in your cPanel, in your .htaccess file, or in your php file. To perform a 301 redirect in your cPanel, under the Domains heading click on Redirects.

Fill in the information required for the redirection, and you are done.

Select the Wildcard Redirect option if you wish to redirect all files within a directory to the same filename in the new directory. For example, if you enable the Wild Card Redirect option and example1.com redirects to example.com, then a visitor who tries to access the http://example1.com/pic.jpg URL redirects to the http://example.com/pic.jpg URL.


To do a 301 redirection in your PHP file, put in this code in the old page:

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.newdomain.com" );
?>

To do a 301 redirection in your .htaccess file, you may add in the following codes:

Redirect an old page URL to a new page URL:

Redirect 301 /old-page/ http://www.mysite.com/new-page/

Redirect root domain to new domain:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [NC]
RewriteRule (.*)$ http://newdomain.com/$1 [R=301,L]
</IfModule>

How helpful was this article to you?