
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:
- You have changed your domain name and want to redirect visitors from the old domain to your new one.
- You have changed an individual page URL and don’t want your users to see a 404 (not found) page.
- 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:
- Log in to your domain registrar (the place you bought the domain, for example GoDaddy or Namecheap).
- Go to “Manage Domains” (or similar).
- Select URL forwarding (or similar – it might differ depending on who your registrar is).
- 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).
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:
- 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”.
- 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##
- ##Permanent URL redirect Start##
- 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”).
- 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.
- 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:
- 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”.
- 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]
- RewriteEngine on
- Replace “example.com” on lines 2 and 3 with your root domain (for example, piccana.co.uk).
- Save your .htaccess file and you’re good to go!
Force visitors to use non-www:
- 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”.
- 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]
- RewriteEngine on
- Replace “example.com” on lines 2 and 3 with your root domain (for example, piccana.co.uk).
- 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.