301 Redirect

SEO Glossary
Contents
  1. What is a 301 redirect?
  2. Do 301 redirects affect SEO?
  3. The difference between 301 and 302 redirects
  4. How to change 302 redirect to 301
  5. Issues with 301 redirects
  6. Entire domain Redirect from non-WWW domain to WWW with prefix #
  7. Vice-versa (from WWW to non-WWW)
  8. For HTTP Version
  9. For HTTPS Version:
  10. Redirect an old page to a new page
  11. In some cases, redirection via RewriteRule is useful
  12. 301 Redirect for web page with GET parameters #
  13. 301 Redirect from web page with not set GET parameter to homepage page
  14. 301 Redirect for specific file and not the whole directory
  15. 301 Redirect from old domain to a new one
  16. 301 Redirect from URLs with no trailing slash to the ones with “/”
  17. 301 Redirect from URLs with trailing slash to the without “/”
  18. 301 Redirect from domain to the folder on another domain
  19. 301 Redirect of all files in the folder to the new URL
  20. 301 Redirect of all the documents in the folder except for one
  21. Change of extension from .html to .php
  22. Transafer of all images from /img/ folder to subdomain
  23. Setting up of index page type (php, html, htm, and others)
  24. 301 Redirect from .php to the root folder
  25. Redirect from subdomain to  #
  26. 301 redirect of specific document in different folders
  27. If you need to make a SEO-friendly address for any document you may perform that with .htaccess file, too
  28. 301 Redirect from HTTPS to HTTP #
  29. Entire domain Redirect from HTTP to HTTPS
  30. Setting 403 Response server response code for referral spam (301 Redirect for spam via REFERER) for list of resources:
  31. Setting the rout to the 404 Error document with .htaccess #
  32. If there is need to perform 301 Redirect only for specific USER_AGENT’s, and not for all visitors
  33. If there is need to perform 301 Redirect for all crawling bots (and you have list of their USER_AGENT’s)
  34. Regular expression syntax
  35. How to do a 301 in Bitrix

What is a 301 redirect?

301 redirect is a permanent redirect of an url to another url which passes all link juice to the recipient. Basically, it is one of the HTTP response status codes indicating that request to the webserver was processed successfully

 

All 3xx redirects refer to Location response headers, one if Standard headers of hyper Text Transfer Protocol. You may find full HTTP response headers list in its specification.

 

Do 301 redirects affect SEO?

According to Search Engine Land and multiple discussions in the SEO community 301 Redirects are not a Ranking factor. And, technically, it’s true. There is a list of recommendations, when 301 Redirects should be used:

 

  • You are going from HTTP to HTTPS.
  • You are moving from an old domain to a new one.
  • You are optimising URL slugs for existing posts and pages.
  • You are moving to a new website platform and your pages will change from https://domain.com/page.html to https://domain.com/page/.

 

However, if you dig deeper in the logic of how link juice is delivered on the web. You’ll understand more. 

So, as described above, you use page-to-page 301 redirects when you move your website from old domain to a new one, and the structure of the website has not been changed. So, each page of the old domain delivers its accumulated link juice to the same page on the new address. That will help your website not to lose its positions in SERP, and will help to understand Google search engine, that it is the same website with just a new domain name. Pure logic here.

But what if we take another website in the same niche and configure its .htaccess file for page-to-page redirection to our domain? Google will probably start thinking that we are moving the old website to a new domain name. Yes, the structure of two sites is different, but the niche is the same, so everything seems legit, and “link juice” should be delivered. 

So the final answer is that 301 redirects can boost your website if you know how to use them correctly. And in this article we will teach you how.

The difference between 301 and 302 redirects

In the context of website promotion, 301 and 302 redirects control the appearance of pages in search results. A 301 redirect is a signal to the search engine that the old page should be removed from the search results. With a 302 redirect, the original address remains in the search results despite the redirect.

A 302 redirect by seo specialists is used if the site is undergoing temporary technical work and the page content changes for the same limited period of time (for example, a stub is placed on the page “Sorry, the site is temporarily down – technical work is underway”). In other cases, setting up a 302 redirect is not worth it.

How to change 302 redirect to 301

Issues with 301 redirects

How to do a 301 redirect

Entire domain Redirect from non-WWW domain to WWW with prefix #

RewriteCond %{HTTP_HOST} ^site\.com$ [NC]

RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]

Vice-versa (from WWW to non-WWW)

For HTTP Version

RewriteCond %{HTTP_HOST} ^www.site\.com$ [NC]

RewriteRule ^(.*)$ http://site.com/$1 [R=301,L]

For HTTPS Version:

RewriteCond %{SERVER_PORT} ^80$ [OR]

RewriteCond %{HTTP} =on

RewriteRule ^(.*)$ https://pixelplus.com/$1 [R=301,L]

 

Redirect an old page to a new page

Redirect 301 /was.php http://www.site.com/new.php

In this case, the new address must be specified in full with http and domain name.

In some cases, redirection via RewriteRule is useful

RewriteRule ^dir /dir-new/$1 [R=301,L]

 

301 Redirect for web page with GET parameters #

For example URL of the page is: http://www.site.com/dir/index.php?IBLOCK_ID=1&SECTION_ID=111 

Then, for 301 Redirect this rule should be used:

RewriteCond %{QUERY_STRING} ^IBLOCK_ID=1&SECTION_ID=111$ [NC]

RewriteRule ^dir/index\.php$ /new/sef/? [R=301,L]

IF one (or several) of GET parameters are not set or may have random variable (in our case it is SECTION_ID), then you may use this code:

RewriteCond %{QUERY_STRING} ^IBLOCK_ID=1&SECTION_ID=(.*)$ [NC]

RewriteRule ^dir/index\.php$ /new/sef/? [R=301,L]

 

301 Redirect from web page with not set GET parameter to homepage page

If the address is: 

http://www.site.com/?abc 

Then for the 301 Redirect you may use this code:

RewriteCond %{QUERY_STRING} ^abc$ [NC]

RewriteRule ^$ /? [R=301,L]

 

301 Redirect for specific file and not the whole directory

If you need to perform 301 Redirect from

http://www.site.com/dir/ 

to new address, but you need a document

http://www.site.com/dir/index.php?IBLOCK_ID=1

to be available from the old address, you need to use “$” symbol in the rule:

RewriteRule ^dir/$ http://www.site.com/new-dir/ [R=301,L]

 

301 Redirect from old domain to a new one

 

RewriteCond %{HTTP_HOST} ^old-site\.com$ [NC]

RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]

 

301 Redirect from URLs with no trailing slash to the ones with “/”

 

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !\..{1,10}$

RewriteCond %{REQUEST_URI} !(.*)/$

RewriteRule ^(.*)$ http://www.site.com/$1/ [L,R=301]

 

301 Redirect from URLs with trailing slash to the without “/”

 

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} ^(.+)/$

RewriteRule ^(.+)/$ http://www.site.com/$1 [R=301,L]

 

301 Redirect from domain to the folder on another domain

RewriteCond %{HTTP_HOST} ^si-te\.com$ [NC]

RewriteRule ^(.*)$ http://www.site.com/si-te/ [R=301,L]

 

301 Redirect of all files in the folder to the new URL

RewriteRule ^dir(.*)$ /new-file.php [L,R=301]

 

301 Redirect of all the documents in the folder except for one

RewriteRule ^dir/no-file.html /no-file-new.html [L,R=301]

RewriteRule ^dir(.*)$ /all.php [L,R=301]

 

Change of extension from .html to .php

 

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

 

Transafer of all images from /img/ folder to subdomain

RewriteRule ^img/(.+)\.jpg$ http://img.domain.com/$1.jpg [R=301,L]

 

Setting up of index page type (php, html, htm, and others)

Order of document formats to be downloaded:

DirectoryIndex index.html index.php index.htm index.shtml

 

301 Redirect from .php to the root folder

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/

RewriteRule ^index\.php$ http://www.site.com/ [R=301,L]

Same thing for ALL .php documents on the website:

RewriteRule ^(.*)index\.php$ http://www.site.com/$1 [R=301,L]

 

Redirect from subdomain to  #

RewriteCond %{HTTP_HOST} ^test.site.com$ [NC]

RewriteRule ^(.*)$ http://site.com%{REQUEST_URI} [R=301,NC,L,QSA]

 

301 redirect of specific document in different folders

RewriteRule [^abc]/unique-file.html /unique-file.html [R=301,L]

 

Code allows to make a 301 Redirect from all folders:  http://site.com/***/uniqe-file.html to on file in the root folder /unique-file.html. May be useful for website redesign

 

If you need to make a SEO-friendly address for any document you may perform that with .htaccess file, too

RewriteRule ^testing/test/?$ /studio/news/detail.php?ID=230354&PAGEN_2=11 [NC,L]

 

Code allows to create a copy of web page with reladtive address:

/studio/news/detail.php?ID=230354&PAGEN_2=11 with address /testing/test/

 

301 Redirect from HTTPS to HTTP #

RewriteCond %{HTTPS} “on”

RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

 

Allows to remove duplicate URLs with HTTPS in Search Engine index

Entire domain Redirect from HTTP to HTTPS

 

RewriteCond %{SERVER_PORT} ^80$ [OR]

RewriteCond %{HTTP} =on

RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]

Setting 403 Response server response code for referral spam (301 Redirect for spam via REFERER) for list of resources:

RewriteCond %{HTTP_REFERER} ref-spam-site.com [NC,OR]

RewriteCond %{HTTP_REFERER} another-ref-spam.com [NC]

RewriteRule .* – [F]

 

These settings allow to block spammy referral traffic from list of resources with specific header HTTP_REFERER

 

Setting the rout to the 404 Error document with .htaccess #

Attention! This is important for server response code to be 404 for 404 document.

ErrorDocument 404 /404-for-me.php

# All rules are executed in the direct order they appear in the .htaccess file and the rule written later will be executed later.

# For sites that do not use the Apache server, similar 301 redirects are easily configured using PHP.

 

<?php

header(“HTTP/1.1 301 Moved Permanently”);

header(“Location: http://www.site.com/dir/”);

exit();

?>

# It is optimal to configure all redirects to the final page at once (without intermediate redirects, in one step), this improves their perception by search engines and users.

 

If there is need to perform 301 Redirect only for specific USER_AGENT’s, and not for all visitors

RewriteCond %{HTTP_USER_AGENT} (iPad|ipad|iphone|iPhone|ipod|iPod|android|midp|j2me|symbian|series\ 60|symbos|windows\ mobile|windows\ ce|ppc|smartphone|blackberry|mtk|bada|windows\ phone) [NC]

RewriteRule (.*) http://mobile.site.com/ [L,R=301]

If there is need to perform 301 Redirect for all crawling bots (and you have list of their USER_AGENT’s)

 

RewriteCond %{HTTP_USER_AGENT} !(accoona|ia_archiver|antabot|ask\ jeeves|baidu|dcpbot |eltaindexer|feedfetcher|gamespy|gigabot|googlebot |gsa-crawler|grub-client|gulper|slurp|mihalism|msnbot|worldindexer |ooyyo|pagebull|scooter|w3c_validator|jigsaw|webalta|yahoofeedseeker |yahoo!\ slurp|mmcrawler|yandexbot|yandeximages |yandexvideo|yandexmedia|yandexblogs|yandexaddurl|yandexfavicons |yandexdirect|yandexmetrika|yandexcatalog|yandexnews |yandeximageresizer) [NC]

RewriteRule (.*) http://no-search.site.com/ [L,R=301]

 

Regular expression syntax

 

. — The dot replaces an arbitrary character.

[abc] – denotes a list of characters that match the letters a, b, or c. [^abc] – a list of characters that are not included in the specified range. Matches any character except a, b, or c.

* – means that the preceding character can be repeated (0 or more times).

[abc]* – the command will find consecutive characters from the given set. [^abc]* – exactly the opposite.

 

.* – replaces absolutely any set of characters. “.*” – finds all substrings between quotes.

^ – the beginning of a string (if used at the beginning of an expression).

$ – indicates the end of the line.

 

\w is a letter, number, or underscore _.

\d – replaces any digit.

\D – Replaces any character, but not a number.

[0-9] – replaces any number. [a-z] – any letter from a to z (the entire Latin character set) in lower case. [A-Z] – any letter from A to Z in UPPER case. [a-zA-Z] – any letter from a to Z in any case. [a-Z] is the same.

Remove all GET parameters after the question mark (?) #

RewriteRule(.*) $1? [R=301,L]

Position after: RewriteBase /

 

How to do a 301 in Bitrix

 

Redirect from all domain files, except for the administrator folder bitrix #

RewriteRule ^bitrix/ /bitrix/admin/ [L,R=301]

RewriteRule ^(.*)$ http://www.newsite.com/new/ [L,R=301]

SEO Data analyst with years of broad experience in Local SEO, eCommerce, Amazon Affiliate Marketing, and Gambling niche.

Rate author
Add a comment