url redirect

Redirecting all URLs to .com rather than .biz, .co.uk, .info

I was having this problem with my current site. I have several domains like

ukwhitegoods.biz

ukwhitegoods.co

ukwhitegoods.co.uk

ukwhitegoods.com

ukwhitegoods.eu

ukwhitegoods.info

ukwhitegoods.me.uk

Even the problem was Google was indexing all these pages separately and which is not good from the SEO perspective. Therefore, we

This thing is also called as CANONICAL DOMAIN

I used the following code to force all URLs to go to .co.uk

RewriteBase /
 
RewriteCond %{HTTP_HOST} !^(www\.)?ukwhitegoods\.co\.uk$ [NC] ////This means was anything other than this pattern is fired, follow the rule

///NC means case sensitive URL
RewriteRule ^(.*)$ http://www.ukwhitegoods.co.uk/$1 [R=301,L] ////Its a permanent redirect and LAST RULE

So now all my landing pages goes to ukwhitegoods.co.uk

.htacess redirect and rewrites

I am writing this blog for a very simple usage of htaccess for redirects and rewriting the url

The first things that needs to be understand for the htaccess REWRITE and REDIRECT modules are the synstax

 

marks the start of line. It means anything that starts with

$ marks the end of line.

(.*) means any character within the url. This gets replaced by $1 at first occurence and $2 as second occurence

L means last code and do not execute anything after this.

R means redirect the page, so the url will be changed. However if you do not add that, it will be same.

 

 

Now here are some sample code

 

RewriteRule ^styles/ - [L,NC]

Now the above code means that if any url starts with style, just let it go through it. for example

http://www.google.com/styles

 

RewriteRule ^resources/image/thumb/(.*)/?$ /download/file.php?id=$1&t=1 [NC,L] # Handle product requests

If any url starts with resources/image/thumb/(.*){THIS COULD BE ANY STRING}/

http://www.google.com/resources/image/thumb/65/

http://www.google.com/resources/image/thumb/was5/

http://www.google.com/resources/image/thumb/adhg5/

Go to looking for

http://www.google.com/download/file.php?id=$1&t=1

Here $1 is (.*){THIS COULD BE ANY STRING}/

http://www.google.com/download/file.php?id=was5&t=1

http://www.google.com/download/file.php?id=65&t=1

 

 

RewriteRule ^resources/image/(.*)/rokbox.jpg?$ /download/file.php?id=$1&mode=view/rokbox.jpg [NC,L] # Handle product requests

RewriteRule ^(.*)/$ $1.html [R,NC,L] # Permanent Move
RewriteRule ^(.*)/(.*)$ $2 [R,NC,L] # Permanent Move

 

 

To exclude a file from htaccess rule: follow this

RewriteCond %{REQUEST_URI} !^/google89b2a81fd1609a6e\.html$