How to add a 301 redirect? 301 Htaccess Redirect SEO Benefits

Alliance  ·  March 03

Each time you make updates to your website design or are looking to improve your search engine optimization strategy, you will want to take into account common SEO guidelines for 301 Htaccess redirects to make sure you don’t end up with any broken links or inaccessible pages. In this article, we will explain some common guidelines to consider when it comes to 301 Htacess redirects to make updating your website a bit easier.

What is a 301 redirect?

A 301 redirect is a permanent redirect from one URL within a website to another. It is commonly used when making updates to a website’s pages when undergoing a redesign, as well as when changes are made to URLs on a website with the intention to improve search engine optimization strategy. The 301 part refers to the status code of a redirected page, telling a browser that this page has moved permanently. A 301 redirect is a way of indexing, and used to send a visitor from the URL of a previous page to a new URL or website page. Within a full website redesign, 301 redirects will be used when moving all old website pages to the new page designs.

What is an Htacess file?

Htacess stands for hypertext access, and is a type of server configuration file. Each file contains configuration directives towards a server within a directory. In simpler terms, each htaccess file basically gives instructions to a server, which could include passcode requirements for certain areas of a directory, as well as configuration to automatic redirects on certain areas of a website. If you need to update an htaccess file, it is important to ensure the file is properly titled ‘.htaccess’ only.

Common Guidelines for Htaccess 301 Redirects:

Single Page Redirect- Might be used for a new website design or URL link for improved search engine optimization

Redirect 301 /pagename.php http://www.domain.com/pagename.html

Full website redirect- Used for a full redesign of a website

Redirect 301 / http://www.domain.com/

Updating an old to new domain on a website

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Redirects from an old website to new domain with no updates made to the URL path

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]

If you do not want to pass the path to the new domain, change the last line to:

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

Redirect from one directory to another- A website directory contains the URLs for all the content on your website. 

Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $1/new-directory/$2 [R,L]

Subfolder Redirects- A subdirectory is a part of a URL that contains specific types of content on your website. Within each of these subdirectories are subfolders, which house individual pages that relate to these types of content.

Redirect 301 / http://www.domain.com/subfolder/

Redirects to a www subdomain- A subdomain is an additional part of your domain name that allows for better organization and navigation to different sections within a website. Some examples of a subdomain might include a website store or blog.

RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Redirects from a blog subdomain to a folder- You may want to set up a redirect if you want a website blog to be housed as a folder within your content as opposed to its own subdomain.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.somewhere.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www.somewhere.com/blog/%{REQUEST_URI} [R=302,NC]

File extension redirects- File extensions provide a way of labeling names of files to allow you to keep track of them and the content they contain. The last part of the file name is used for indication of what that type of file is. When making updates to a website, you will want these files to redirect appropriately to the updated file extension name.

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

Redirects from HTTPs to HTTPs to avoid duplicate content- Updating your website to include an HTTPs security certificate will help protect visitor privacy and  information from data theft.

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Adding a trailing slash to a URL- A trailing slash is the slash located at the end of a URL link that is used to mark a directory on a website.

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://www.example.com/$1/ [R=301,L]

By using the 301 redirect guidelines mentioned above for different projects on your website design, you will ensure each website page redirects correctly and to the correct piece of content. Some common 301 redirects mentioned above include full and single page redirects, redirects to new domains, and redirects within a directory, subfolder, and file extension on your website, all of which are important to pay close attention to when making any updates to your website in order to provide a great online experience.

Alliance Interactive is a Washington DC based full service digital agency providing website design and development improvements for clients in a number of different industries. Our team of experts can help with a number of different development projects, from everything to domain updates to full website design overhauls and CMS system migrations.