What is a 301 Redirect?

A 301 redirect or 301 moved permanently is an HTTP status code that is used to redirect search engines and users from an old URL to a new URL of a page. 301 redirects also transfer the ranking power of the old URL to the new one.

Does a 301 Redirect Pass the Domain Authority too?

A 301 redirect is a way to tell the search engine to pass all the authority and the ranking to the new URL. However, it is seen that it does not transfer the ranking completely to the new URL; some of the PageRank is lost due to the link to link decay, which is perfectly normal.

When to Use 301 Redirect?

You can use a 301 redirect if:

  • You are changing a URL permanently.
  • You are creating a piece of content again.
  • You want to consolidate multiple contents.
  • You want to transfer your content to another domain.
  • You want to shift a website to a new domain.

What is a .htaccess File?

Htaccess or hypertext access file is a text file used to configure a website in Apache-based servers. It contains a set of instructions to dictate the server’s behaviour on your site.

When can a .htaccess file be used?

A .htaccess file can be used for different purposes, such as:

  • Setting up password protection for your website.
  • Creating a customised error page.
  • Redirecting users.
  • Forcing HTTPS rather than HTTP.
  • Controlling IP access on your website.
  • Customising and makeing user-friendly URLs.
  • Enabling compression for faster page loading times.
  • Controlling browser and proxy caching to improve website performance.
  • Specifying how the server handles certain file types.
  • Blocking access from malicious bots or spammers.
  • Preventing other websites from directly linking to your resources.
  • Defining the default page for directory access.

How to Create a .htaccess File?

A .htaccess file is pretty easy to create. You can do it in the following simple steps:

  • Create a file with MS Word, notepad or any other text editor.
  • Write your set of instructions in that file.
  • Rename your file to .htaccess and upload it using an FTP client.

How how to do a 301 redirect Using .htaccess File?

A .htaccess file can be used to create the following 301 permanent redirects:

  • For a single URL on the same domain
  • For a single page to a new domain
  • for a single folder
  • from a non-www URL to a www URL
  • from a www URL to a nor-www URL
  • for a new domain
  • For redirecting from HTTP to HTTPS

You will need to use RewriteEngine in the modrewrite module in Apache for 301 permanent redirects using .htaccess file. This mode is loaded by default, but if it is not loaded, you can use the following directives:

<IfModule mod_rewrite.c>

RewriteEngine On

</IfModule>

Once the module is loaded, you can use a different set of rules to enable 301 permanent redirects. Which we have explained below:

For a Single URL On the Same Domain

If you want to redirect one URL to another URL using .htaccess file, you can use the following rule:

RedirectMatch 301 / old-page/ /new-page/

Make sure to write exact URLs in the rule to make it work. You will have to mention the RUL path in the first part and an absolute URL in the second path.

For a Single page to a New Domain

If you want to redirect a single page to a new domain using .htaccess file, you can use the following rule:

Redirect 301 /old-page/ https://www.yourdomain.com/new-page/

Make sure you verify URLs before adding them to the rule. For the first half, you can just add URL path, but for the second half, you will have to put a complete URL.

For a Single Folder

If you want to redirect an entire folder to a new URL, such as if you want to redirect your blog folder to news, you can use the following rule:

RewriteRule ^/?blog/(.\*)$ /news/$1 [R,L]

In the above rule, “blog” and “news” are used as an example of 301 redirect using .htaccess file. Make sure that you use actual folder names from your website in order to make this work.

From Non-www URL to a www URL

If you want to redirect URL non-www URL requests from search engines and users to a www URL, you will have to use the following rules:

RewriteCond %{HTTP_HOST} \*!^www\*.example.com [NC]

RewriteRule (.\*) http://www.example.org/$1 [L,R=301]

Make sure that you put the exact domain name in the rules to make it work.

From a www URL to a nor-www URL

If you are not using the www subdomain and want to redirect the requests of search engines and visitors from the www URL to a non-www URL, the following set of rules will apply:

RewriteCond %{HTTP_HOST} ^www.example.com$

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

For a New Domain

If you have shifted your website to a new domain and you want to transfer your organic traffic and ranking power to your new domain name, you can use the following rules:

RewriteEngine on

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

For Redirecting from HTTP to HTTPS

If you want to redirect your entire domain from HTTP to HTTPS, the following set of rules will apply:

RewriteEngine On

RewriteCond %{HTTPS} off

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

What to do If a 301 Redirect Using .htaccess file is Not Working?

You can follow these steps to fix your misbehaving 301 redirects.

  1. Verify the URLs by visiting the websites.
  2. Check for any linking errors in your .htaccess file from the root directory of your website.
  3. You can also use a third-party tool to check your 301 redirects.
  4. Look for any misbehaving file from your server logs.
  5. Look for redirect chains or loops and remove them.
  6. Check the sitemap for any broken redirects and fix them.

Other 3xx HTTP Status codes

  • 300 – Multiple Choices
  • 302 – Moved Temporarily
  • 303 – See Other
  • 304 – Not Modified
  • 305 – Use Proxy
  • 306 – Unused
  • 307 – Temporary Redirect
  • 308 – Permanent Redirect