Htaccess 301 redirect for dynamic pages that already have URLs rewrote w/ mod_rewrite

Hi,

All the main dynamic pages for the product pages are setup with mod_rewrite like this:

dynamic pages like this:
http://www.examples.com/product-details.php?listing=product-name-goes-here

are re-written to pages like this:
http://www.examples.com/product-name-goes-here-keyword

*The “-keyword” text used in the re-written pages is used to ensure the pages are redirected to the correct landing page.

The problem I have is that many of the original dynamic pages are indexed in the search engines along with the re-written versions which are causing duplicate content issues. How can I setup a single rule to 301 redirect ALL of the dynamic pages over to the re-written versions? I know I can manually set the 301 redirects, but that would require us to add a new redirect for every new product that is added, so that doesn’t seem like the best choice for this project.

The following is where I’m at right now with it, but it’s not working:


RewriteEngine On  
RewriteCond %{REQUEST_URI} ^/product-details\\.php [NC]
RewriteCond %{QUERY_STRING} ^listing=([A-Za-z0-9_-]+)$
RewriteRule ^/product-details\\.php?listing=([A-Za-z0-9_-]+)$ /$1-keyword [R=301,NC]

dev,

From your post, it appears that you’re attempting the “loopy” redirection as it’s not likely that you can serve http://www.examples.com/product-name-goes-here-keyword. I have a section about “loopy redirection” with sample code in the latter part of my signature’s tutorial.

Regards,

DK