Removing Duplicate URL problem

Discuss practical ways rearrange URLs using mod_rewrite.

Removing Duplicate URL problem

Postby ezee » Thu Jul 02, 2009 2:30 am

I have a site which uses mod_rewrite for rewriting pages to SEO freindly url's, like:

http://www.example.com/details.php?id=myid
to
http://www.example.com/myid-page.html

now the problem is somehow the first page with query string got indexed in google and I want to now do 301 permanent redirect on above page to .html page.

But when I try to use, I get following problems:

- "Redirect 301" does not works because it has a query string
- RewriteRule with RewriteCond takes it in a loop, given below the rule I am using:

RewriteCond %{QUERY_STRING} ^id=myid$
RewriteRule ^/details\.php http://www.example.com/myid-page.html? [R=301,L]

Can any one suggest how to avoid user typing urls with querystring, which should auto redirect to the HTML version?
ezee
 
Posts: 3
Joined: Wed Jun 17, 2009 4:03 am

Postby richardk » Fri Jul 03, 2009 8:46 am

You can use
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

to stop loops. It will only have a value (a HTTP status code) after a rewrite has occurred.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?id=myid(&.*)?$ [NC]
RewriteRule ^/details\.php http://www.example.com/myid-page.html? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 33 guests

cron