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 http://www.domain.com/about-us.html http://www.domain.com/about.htmlUsing PHP
<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.domain.com/about.html" );
?>
What i want is to redirect dynamic urls(with query string , ? and &) to static page. For e.g. If i want to redirect http://www.domain.com/content.php?a=1&b=2 to http://www.domain.com/content.html than look at the below htaccess rules.
RewriteCond %{HTTP_HOST} ^domain.com
RewriteCond %{QUERY_STRING} ^a=1&b=2$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/content.html [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 http://www.domain.com/content.php?a=1&b=2 , it will redirect to http://www.domain.com/content.html. 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.






I am
about 2 years ago
thanks for your useful article
about 2 years ago
thanks for your useful article
about 2 years ago
hi
i used this code by .htaccess for change this address:
http://advertise.mirsoft.net/detail.php?siteid=3
to :
http://advertise.mirsoft.net/detail-3.html
but the cod dose not work
help me please.
thanks
about 2 years ago
hi
i used this code by .htaccess for change this address:
http://advertise.mirsoft.net/detail.php?siteid=3
to :
http://advertise.mirsoft.net/detail-3.html
but the cod dose not work
help me please.
thanks
about 1 year ago
Awesome – I can feel that I’m getting close with this article… Rakshit, how would you do this if the page that was taking the query string was not the root?
For instance, we want to redirect:
http://www.mydomain.com/main/some-page.asp?p=30 –> http://www.mydomain.com/newpage
If you could solve this, it will make my entire year. Many many thanks my friend,
Arsham
about 10 months ago
Thanks for this. I’ve been having problems with redirecting a page that doesn’t exist any more to a new page on my blog about mens slim fit shirts at http://www.menslimfitshirts.co.uk
about 8 months ago
Hey Rakshit i have an issue i want to redirect my dynamic url to a static one so that i can remove the quotes and other unwanted marks,, just let let me know is that possible to add only one hta access file at toot folder or we need to add this file to every folder we have.
about 7 months ago
Thank you very much,
It helped me,
more sources to help people that asked more questions, it will help!
And someone made an excel file, that make the code automatically (including dynamic links to dyanmic\static links):
Good Day,