Skip to content

Code Snippets To Implement 301 Redirect – woorkup.com

Link To Full Story: woorkup.com

Redirect 301 with htaccess

In my opinion htaccess is the best and quickly way to redirect your pages. Only an advice: you need to have a base knowledge of htaccess for use it or you risk to have some serious problems on your site! So, before start using htaccess, I suggest you some good reading: Complete guide to htaccess for Beginners and Htaccess tutorials on apache.org.

Here is an example of htaccess usage:

Redirect permanent http://mysite.com 
http://www.mysite.com

Now supposed you have the following two URLs: http://www.mysite.com and http://mysite.com. For Google, for example, these URLs are two different pages and their page rank will be divided among two pages. So, why not using htaccess to redirect all traffic to only one page?

The only thing you have to do is to create a new file called .htaccess with the following code:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !^mysite\.com [NC]
   RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301]
</IfModule>

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*