Tuesday, June 22, 2010

How to do custom redirection of a website

Usually the redirection needs when a website changed/move to different location though it may use for lots of other purposes. In this post, I have explain how you can do it by using .htaccess

Say, your site has lots of URL and you want to redirect some of those which query string has a parameter name “option” and the value is “redirect”.

Below are the codes to redirect into new URL:
RewriteEngine on
RewriteCond %{QUERY_STRING} option=redirect
RewriteRule (.*) http://newsite.com/index.php?%{QUERY_STRING} [R=301,L]

Just copy above lines into .htaccess file and place it to root directory in your application.

Some helpful posts:


  1. Very nice post! Thank you very much for this post. I was blocked for this stuff because i have changed my site and wanted to redirect few URLs to my new location. I did it successfully. Thanks again for your nice post..

  2. nice article...tq for sharing