301 redirect to avoid duplicate content issue

tomaszjot

Membership Suspended
Dec 22, 2009
1,934
77
0
Albany Plantation
I've already checked a lot of resources all over the Internet but could not solve this issue.

I have a very old site, custom built, which had this silly structure like:

examplesite.com/example.php?id=1777

With my unfulfilled coder ambition I decided to clean up URLs to:

examplesite.com/example/1777

To achieve this I used:

RewriteRule ^example/(.*)/?$ example.php?id=$1 [L]

and it pretty much is a zenith of my abilities.

So I left it for a while, traffic dropped to minimum and I reminded myself that this rewrite generated a lot of duplicate content.

So my question is - how do I make sure only /item/177 version is accessible/indexed? I guess 301 will do but how?

It's not an important issue but something which makes my brain itchy since it's a unsolved problem...

Thank you for attention and any help.
 


Not sure if I understand the question, but in your mod_rewrite rule just change the "[L]" at the end to "[R=301,L]".

Right now it'd be redirecting with a 302 code (moved temporarily).
 
Setting the canonical URL of the page (to the URL that you would prefer to use) will solve any issues with duplicate URLs caused by query string data

e.g.

Code:
http://examplesite.com/example/1777?DUPLICATE

As far as I know, the current `RewriteRule` you are using isn't a redirect but a regular rewrite so you won't need to worry about `301` or `302` status unless you want the old format URL to be redirected to.

It would be useful to redirect all the old format URLs to the new format though via a `301` redirect so you might want to add a suitable `RewriteRule` for that. This is especially true if your site is still using URLs in the old format, which should ideally be updated to minimise redirects.