This isn't a mod rewrite before all you exciteable MOD rewriters get turned on. I am doing a mod rewrite but this part is to regenerate the HTML code. I have the link $link = "www.domain.com/index.php/cPath/35_120_134"; and I want to turn this into www.domain.com/category_name-35-subcategory_name-120-subsubcategory_name-134.html I've been using lots of strpos and substr's but I thought there might be an easier way of doing it. Anyone got any ideas?
So you Mod rewrite it first and then take the raw text and let PHP take it apart? Considering www.domain.com/index.php/cPath/35_120_134 is already rewritten, why not amend your re-write rule? Sounds like a mighty complicated way of doing it.
Its because the previous designers have messed the whole site up and it would be a complete site redesign if I wanted to try and do it the "proper" way. Woops by the way. I meant to put http://www.domain.com/index.php?cPath=35_120_134
Try browsing around this site: http://rewrite.drbacchus.com/rewritewiki/FrontPage i got the url in an IRC chanel and it seems to have a lot of great info on mod_rewrite, and it also has a solution for your issue.
Nah, I know how to mod rewrite stuff. Its more replace functions in PHP I'm looking for. Thanks for the resource though
OTTOMH: Explode the URI by "/". $uri_parts = explode("/", $uri); $part_to_rewrite = $parts[3]; Explode last part by "_". $id_parts = explode("_", $part_to_rewrite); Search category name: $name1 = SELECT category_name from categories WHERE id = $id_parts[0]; $name2 = SELECT category_name from categories WHERE id = $id_parts[1]; $name3 = SELECT category_name from categories WHERE id = $id_parts[2]; $new_url = $parts[0] . '/' . $name1 . '-' . $id_parts[0] . '-' . $name2 . '-' . $id_parts[1] . '-' . $name3 . '-' . $id_parts[2] . '.html'; // Code for illustrational purposes only.