Adding 301 Redirects using htaccess

It's easy adding 301 redirects to your website using Apache's htaccess. A 301 redirect is the most efficient and Search Engine Friendly method for web page redirection. It's not difficult to implement and will preserve your search engine rankings as well.

Often when someone does a redesign of their website or puts it into a new platform, and little consideration is regarded for the difference between the existing an new link structure. You should have a redirect in place if your old link structure varies from the new one. This will help you maintain you search engine rankings and decrease the possibility if someone reaching a 404 page.

Below is one variant of a 301 that redirects when someone tries to access your website without the (www); It will redirect the URL to your website with the www. You should choose which variation your website should stick with because accessing your website both ways is bad for Search Engine Optimization.

So, to implement this type of redirect for your website, follow these instructions:

  1. Open up notepad or any other text editor and copy and paste the commands below.
  2. Change (yourdomain) to your domain name.
  3. Save the file with this name: (.htaccess). There is no file name. If you have a problem doing this on Windows, read this article.
  4. Upload it to the root directory of your website.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

2 comments for Adding 301 Redirects using htaccess

Jerry's picture

This was so incredibly...

This was so incredibly helpful! Thank you for sharing this!

tom's picture

This was a pretty good post...

This was a pretty good post

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.