Sunday, May 29, 2011

301 Redirect old dynamic URLs to new static URLs using .htaccess

Hello Friends,
Today i faced a situation where i need to redirect dynamic URL of my shopping cart to static url. I have changed the Dynamic URL(with query string , ? and &) to static one in my sunshop shopping cart. But still if i will open dynamic url with query string than it shows the content. This is a big issue with search engine as they will consider this dynamic page and static page as two different page and duplicate content issue araise.
Redirect 301 rule in .htaccess (which is below) is common rule everybody knows.
Using .htaccess
redirect 301
Using PHP
What i want is to redirect dynamic urls(with query string , ? and &) to static page. For e.g. If i want to redirect to than look at the below htaccess rules.
RewriteCond %{HTTP_HOST} ^
RewriteCond %{QUERY_STRING} ^a=1&b=2$ [NC]
RewriteRule ^(.*)$ [R=301,L]
Add the above three lines and change the domain name and query string as per your need. Now whenever you will enter , it will redirect to So now Search engine will consider both as one page and duplicate content issue will not araise.
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database,php info,php editor,programming php,Open-source,php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.


  1. I tried your code but it append query string in the static url. What is the solution?

  2. Bala, Code is already tested, can you post your code ?