301 Redirect Methods and Examples

What is a 301 Redirect? What is it used for? How do you correctly set it up on your website? We will try to answer these questions.

301 Redirect Methods and Examples

What is a Redirect?

Redirect is a way to redirect users and search engines from one url to another.

  • 301 Moved Permanently
    301 Redirect is  permanent. It allows preserving about 90-99% of a search engine rank. This redirect indicates that the page was moved to a new address and that the old url will be considered outdated.
  • 302 Found (HTTP 1.1) / Moved Temporarily (HTTP 1.0)
    302 Redirect is a temporary redirection. This redirect does not preserve a search engine ranking.
  • 307 Moved Temporarily (HTTP 1.1 Only)
    307 Redirect in Protocol HTTP 1.1 has become a successor to a 302 Redirect. While main crawlers will consider it a 302 redirect analogue, it is better to use a 301 redirect for almost all cases.
  • Meta Refresh Redirect
    There are also other types of redirects: Meta Refresh or JavaScript-assisted that are executed on the level of a page, not a server. This is how a typical Meta

Refresh redirect looks like:

<!DOCTYPE html><html><head><meta http-equiv=”refresh” content=”0; url=http://www.new-domain.com”></head><body></body></html>

Spammers like using such redirects to create doorway pages. Meta refresh redirect preserves almost no search engine ranking.

How to use a 301 redirect when changing a domain name

So, you bought a new beautiful domain with a good history, or you just don’t like the old one anymore. Do you need to move the website to a new domain, and at the same time not lose search engine rank and Google loyalty?

Set up a redirect on your new website and very soon your domain will appear in google search engine results.

301 htaccess redirect:

RewriteCond %{REQUEST_FILENAME} robots.txt$ [NC]RewriteRule ^([^/]+) $1 [L]RewriteCond %{HTTP_HOST} !^www\.domain\.comRewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

301 Redirect Generation

If you do not feel confident, you can use our redirect generator

You can paste the links in the corresponding fields and receive the completed code for your website.

How to check a 301 redirect

It is very important to understand that you have set up your redirect correctly. Otherwise you may lose search engine ranking, as well as Google loyalty.

How to check if a redirect work:

  • Enter the main page. It should redirect you to the necessary address.
  • Check all main sections of the website.
  • We recommend using our Redirect Checker service to check.

301 Redirect samples

Domain Redirect from www to non-www

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

Domain Redirect from non-www to www

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

Canonical trailing slash
You can set up 2 types of urls at your website:

  • With a trailing slash
    http://domain.com/page/
  • Without a trailing slash
    http://domain.com/page

Google sees urls of different types (with and without a trailing slash) as different pages.  That is why it is important to use only one url type.

301 redirect example to delete a trailing slash

RewriteCond %{HTTP_HOST} (.*)RewriteCond %{REQUEST_URI} /$ [NC]RewriteRule ^(.*)(/)$ $1 [L,R=301]

301 redirect example to add a trailing slash

RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_URI} !(.*)/$RewriteRule ^(.*[^/])$ $1/ [L,R=301]

Page to Page 301 Redirect example

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

Redirect for the main page duplicates
This redirect is used for the redirection of any home page address to the main home page address.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index|main)\.(html|php|htm)\ HTTP/ [NC]RewriteRule ^(([^/]+/)*)(default|main|index)\.(html|php|htm)$ http://www.domain.com/$1 [L,R=301]

Directory Redirect

This method is used if your website has a catalogue structure depicted in the url (/catalog-category/) and you need to change the url .

RewriteRule ^(.*)/old-catalog/(.*)$ $1/new-catalog/$2 [R=301,L]

But if the old catalogue url starts directly after the domain name: www.domain.com/old-catalog/, the following code shall be used

RewriteRule old-catalog /(.*) / old-catalog /$1 [R=301,L]

Redirect when changing the file extension
For example, if you had .php and now you need .html, you need to make the following redirect:

RedirectMatch 301 (.*)\.php$ http://www.domain.com$1.html

How to make a redirect from any url only to a lower case url

Google considers a letter case in an url. It is desirable for all urls to be in a lower letter case.  

But if you made a mistake, the following redirect will help you:

$lowerURI=strtolower($_SERVER['REQUEST_URI']);if($_SERVER['REQUEST_URI']!=$lowerURI){header("HTTP/1.1 301 Moved Permanently");header("Location: http://" . $_SERVER['HTTP_HOST'] . $lowerURI);exit();}

301 redirect vs Canonical

How does google understand a redirect value?

301 redirect

-hey, Google! This page is no longer here. It was permanently moved to a new url. Please delete this address and register a new one.

Canonical

-hey, Google! This page has several versions! Please add only the canonical one in the index-linking. Also, redirect to it the search engine rank of other pages (duplicates)

Use a 301 redirect

  • For pages: if the page was permanently moved or its address was changed
  • For domains: if the website was moved to a new domain
  • For 404 pages and pages with an outdated content

Use rel=”canonical”

  • When the use of 301 redirects is difficult to implement or it would take too much time
  • When you cannot get rid of the content duplication
  • When the website possesses similar pages with different urls. For example, news sorting (by type and date)

Both a 301 redirect and Canonical help preserve a search engine rank and will be similarly considered by Google. But a 301 redirect is a preferable method.

Mistakes in using redirects

  • Any multi-step redirect. It is better to avoid multi-step redirects if there is an opportunity, both for the purpose of quicker use and for the transfer of a maximum search engine rank.
    Use of an incorrect redirect type. When choosing the redirect type, you need to consider the specifics of each of them.
  • Implementation of internal redirects without changing links into new addresses. After all redirects on the website are implemented, it is necessary to check that each page of your website is already linked to the new one and that within the website you do not have links to the pages with redirects.
  • Incorrect use of rel=canonical or a 301 redirect.
  • The redirect with the final point which is not 200 page. A redirect should lead to the correct page with a 200 server response. Otherwise, it is better not to interfere with crawlers and to provide 404 response. Use redirect checker

I hope that this article would help you set up your first redirect!