I was never really quite sure how to do a 301 redirect and was never successful when trying to use cPanel, but I have finally got it working as I would like
Let's back up a second.....what the heck is a 301 redirect? A 301 redirect permanently redirects a certain url to another url. There are a couple of reasons this could be useful, but the reason I want to do it is to ensure that all queries to my website land up at the same URL.
I have two domains, engineersimplicity.com and engineersimplicity.co.za. Both domains point to the same content. This can potentially be a bad thing from a SEO perspective. I always want the search engines to use a particular domain, and that is www.engineersimplicity.com.
So, by setting up the correct 301 redirects browsers will now always land on www.engineersimplicity.com, even if they typed in engineersimplicity.com, engineersimplicity.co.za or www.engineersimplicity.co.za. This is good for me, for the website users and for the search engines.
Here are the instructions for setting up 301 redirects. I did it using the .htaccess file which is available on all Apache web servers.
Here is the code I added to the .htaccess file (change yourdomain to your domain )
PHP Code:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^yourdomain.com [nc]
rewriterule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]
rewritecond %{http_host} ^yourdomain.co.za [nc]
rewriterule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]
rewritecond %{http_host} ^www.yourdomain.co.za [nc]
rewriterule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]
[EDIT] This still isn't working quite how I would like it to. If I go to a specific page it stays on that domain, rather than going to the other domain. I'll update this when I figure it out - or does someone here have some tips? Whoops, scratch that, it does work properly.
Did you like this article? Share it with your favourite social network.