Inbound Marketing Bolton Call us on: 0161 818 9093
  • Home
  • SEO
    • Free SEO Audit
    • SEO for Bitcoin
  • PPC
  • Social
  • ORM
  • Blog
  • Contact Us
    • About Us & FAQs
    • Careers at Piccana

How to set a 301 redirect in .htaccess

13 Jul 2015
In: Internet

how to create a 301 redirect in .htaccess

If you have a website, either for business or personal use, the chances are that one day you will need to set up a 301 redirect – but what is a 301 redirect? Well quite simply a 301 redirect is a way of telling a visitor to your website that the page they are trying to view (or sometimes your whole website) has moved elsewhere, and then redirecting them to the new location. It might sound complex if you’re not a computer whizz, but by following our simple guide you can set one up in no time. It’s important to know that a 301 redirect is classed as a permanent redirect. If only moving a page for a short time (this is very rare), you would use a 302 redirect. The great thing about 301 redirects is that they pass between 90-99% of the “link juice” from your backlinks, so your pages search engine rankings won’t suffer.

Why would I need a 301 redirect?

Good question! There’s many reasons people end up needing a 301 redirect on their site, but the most common are:

  1. You have changed your domain name and want to redirect visitors from the old domain to your new one.
  2. You have changed an individual page URL and don’t want your users to see a 404 (not found) page.
  3. You want visitors to only be able to access your website with or without the “www.” prefix.

The three points above are the most common reasons. If any of these apply to you then use one of our handy templates below to quickly add a 301 redirect to your site. It’s easy when you know how!

I changed my domain name

So you have a new, super cool domain name – but people keep visiting the old one! This is a super easy fix, and we don’t even need to touch the .htaccess file for it (more on that later). Time to redirect them with a 301 redirect by doing the following:

  1. Log in to your domain registrar (the place you bought the domain, for example GoDaddy or Namecheap).
  2. Go to “Manage Domains” (or similar).
  3. Select URL forwarding (or similar – it might differ depending on who your registrar is).
  4. Simply enter your new domain in to the URL field and select “URL Redirect” or “301 Redirect” from the drop down box, as show below (we used Namecheap for this example).

URL redirect namecheap

I changed a page URL to a new location

This one is a bit trickier than a simple domain name change, but it’s still easy enough to do. You’ll need to do the following:

  1. Log in to your hosting panel (for example cPanel) or via FTP/SFTP and open the file called “.htaccess” (notice the dot at the start, it’s not a file extensions but the actual file name itself). You may need to enable viewing of hidden files/dotfiles to view this. If you can’t see it anywhere, simply make a new file and call it “.htaccess”.
  2. Add the following code to the top of your .htaccess file:
    • ##Permanent URL redirect Start##
      Redirect 301 /myoldpage http://www.website.com/mynewpage
      ##Permanent URL redirect End##
  3. Replace “/myoldpage” with the URL of your old webpage. Be sure to use the URL AFTER the .com/.co.uk etc (so for example, for website.com/oldpage you would swap “/myoldpage” for “/oldpage”).
  4. Replace “http://www.website.com/mynewpage” with the FULL URL (so include http:// and also www. if you use it on your site) of the new page location.
  5. Save the .htaccess file and visit the old page URL. It should now redirect to the new page!

 

I want visitors to use/not use the www. prefix

When using “www.” on your website you’re actually adding a sub-domain (the www. part) to your root domain (the domain you registered, for example piccana.co.uk), which means you’re essentially creating two separate, but identical, websites. Because of this you should decide on using either www or non-www and forcing your chosen version upon visitors with a 301 redirect. This means that any links pointing to your site are all redirected to exactly the same page, and the link equity/link juice is not wasted. It will also help solve any issues relating to duplicate content within your own website.

Here’s how to force visitors to use the www. prefix:

  1. Log in to your hosting panel (for example cPanel) or via FTP/SFTP and open the file called “.htaccess” (notice the dot at the start, it’s not a file extensions but the actual file name itself). You may need to enable viewing of hidden files/dotfiles to view this. If you can’t see it anywhere, simply make a new file and call it “.htaccess”.
  2. Add the following 301 redirect code to the top of your .htaccess file:
    • RewriteEngine on
      RewriteCond %{HTTP_HOST} ^example.com [NC]
      RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
  3. Replace “example.com” on lines 2 and 3 with your root domain (for example, piccana.co.uk).
  4. Save your .htaccess file and you’re good to go!

Force visitors to use non-www:

  1. Log in to your hosting panel (for example cPanel) or via FTP/SFTP and open the file called “.htaccess” (notice the dot at the start, it’s not a file extensions but the actual file name itself). You may need to enable viewing of hidden files/dotfiles to view this. If you can’t see it anywhere, simply make a new file and call it “.htaccess”.
  2. Add the following 301 redirect code to the top of your .htaccess file:
    • RewriteEngine on
      RewriteCond %{HTTP_HOST} ^www.example.com [NC]
      RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]
  3. Replace “example.com” on lines 2 and 3 with your root domain (for example, piccana.co.uk).
  4. Save your .htaccess file and you’re good to go!

 

There we go – it wasn’t too hard after all! If you need any help in configuring redirects on your website feel free to get in touch with us, we’re always happy to help.

Need help with redirects?

 

Leave a Comment! Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts

  • 10 Tips for Google AdWords for Business
  • 5 Amazing Tools for Web Designers
  • It’s complicated. It’s dead. Why use Google+?
  • Social Media Monthly Users Infographic
  • How to set a 301 redirect in .htaccess

Categories

  • Bitcoin
  • Election
  • Food
  • Infographics
  • Internet
  • Marketing
  • Remote Working
  • Self-Employment
  • Social Media
  • Unrelated
  • Web Design

Recent Posts

  • 10 Tips for Google AdWords for Business
  • 5 Amazing Tools for Web Designers
  • It’s complicated. It’s dead. Why use Google+?

About Us

Based in Bolton, United Kingdom, Piccana Digital is an inbound marketing agency with an emphasis on our wholly honest approach.

We offer inbound marketing services such as SEO, PPC, Social Media and more to clients across the UK and worldwide, helping them to grow their business and providing them with a positive return on their marketing investment.

With over 10 years experience in the inbound marketing industry, you can be sure your business is in good hands.

Our Services

  • SEO
  • Pay Per Click
  • Social Media
  • ORM

Contact Us

Your Email (required)

Your Message

Inbound Marketing Bolton © 2015 Piccana Digital. All Rights Reserved.