url rewrite & redirect question

Posted by Shawn on Stack Overflow See other posts from Stack Overflow or by Shawn
Published on 2010-05-11T00:31:56Z Indexed on 2010/05/11 0:44 UTC
Read the original article Hit count: 349

Filed under:
|

Say currently I have url like :

http://mydomain.com/showpost.php?p=123

Now I want to make it prettier :

http://mydomain.com/123/post-title

I'm using apache rewrite which grabs segment '123' and put the url back to

http://mydomain.com/showpost.php?p=123

OK. Here is the problem. I want to redirect the original non-pretty urls which were indexed by Google to the pretty versions, I want this because I heard that Google may punish me if he sees multiple urls pointing to identical content. So I need to

redirect /showpost.php?p=123 to /123/post-title

This I have to do in my php code coz there's no way Apache to be able to figure out the 'post-title', but if I put the redirect code in php code, then it will be a infinite loop, such as :

Request : /showpost.php?p=123

redirected to : /123/post-title

rewritten to: /showpost.php?p=123

redirected again to : /123/post-title

...

So on and so forth.

Sorry I should Google the solution first but I really don't know how to describe my situation in English to make Google return reasonable results.

Please help me. Thanks.

© Stack Overflow or respective owner

Related posts about redirect

Related posts about rewrite