Portal Home > Knowledgebase > Articles Database > need help for 301 redirect of dynamic urls


need help for 301 redirect of dynamic urls




Posted by Abh_Empire, 11-05-2010, 08:18 PM
Hello, i have friendly urls active on my website, but the old ones still work, and google keeps indexing them instead of the pretty ones. The platform this is on is called prestashop. So i need to redirect this kind of urls: site.com/category.php?id_category=20 site.com/product.php?id_product=398 to this kind of urls: site.com/the-name-of-category-with-id20 site.com/the-name-of-category-with-id20/the-name-of-product-with-id398.html I've kept reading for the last 2 days about htaccess but i guess i'm just too dumb to figure it out. Last edited by Abh_Empire; 11-05-2010 at 08:22 PM.

Posted by methodical, 11-12-2010, 10:29 AM
Hey Abh, Just thought I would quickly provide a little insight here. What you're trying to do requires more than just .htaccess. The main issue I see here is that there's no way for .htaccess to magically come up with "the-name-of-category" to convert this URL: site.com/category.php?id_category=20 to this: site.com/the-name-of-category-with-id20 Really, you should be posting your question to this forum: http://www.prestashop.com/forums/ I bet there's someone else who has encountered this issue before that might have an answer for you there. I hope this helps. :-) Jeremy

Posted by Abh_Empire, 11-12-2010, 01:51 PM
Thank you, Jeremy, there already exists a php module doing what i want, but it's not free. I figured the same thing could be done with .htaccess, but if you say it can't... well, now i'm sad and on the brink of suicide. Kidding, tx for the reply, i'm convinced now i need php to do it. This may be the reason no one answered to my question on the countless forums i asked.

Posted by methodical, 11-12-2010, 02:13 PM
If you're not afraid to play with some PHP code then what you're trying to do wouldn't be all that hard. Here's a quick outline of the code you would add to the top of category.php: # was the id_category parameter sent? if( $_GET['id_category'] ): # yes, lookup the correct page.... $result = mysql_query("write a query to lookup the right page"); $RedirectURL = "build url based on mysql results"; header("Location: {$RedirectURL}",TRUE,301); exit; endif; Another option would be to setup a .htaccess file that redirects every single old URL to the new one, like this: redirect 301 /category.php?id_category=20 http://site.com/the-name-of-category-with-id20 What I'm saying here is that if you don't have too many products you might just hand-code a redirect for every single product. I hope this helps. :-) Jeremy



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read


Language: