CodeIgniter Forums
I need help with the CodeIgniter routes... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forum-18.html)
+--- Thread: I need help with the CodeIgniter routes... (/thread-63620.html)



I need help with the CodeIgniter routes... - JoelPiccoli - 11-20-2015

Hello everyone,

I'm in the middle of some little problem here in a ecommerce that we are about to launch. The thing is that this ecommerce it's a new version of a older application that this client already have, and for the purpose of not losing the google adherence of the urls I need to accept this kind of url,

Code:
https://biocarers.com.br/index.php?id_menu=produto&id=92&titulo=Product-title-goes-here

and find the product page in the same way of the url

Code:
https://biocarers.com.br/produto/92/Product-title-goes-here


The are any chance of do this with CI routes? 'couse I've tried this and got no results... any ideias? ;/


RE: I need help with the CodeIgniter routes... - stuart8972 - 11-20-2015

I believe CodeIgniter Routes are only useful when mapping from one CodeIgniter URL structure to another - not when working with different systems.

I suggest using Apache Mod Rewrite (or the equivalent for your webserver), which lets you use Regular Expressions to rewrite one URL structure to another. I'm not familiar enough to provide you the rules quickly, others may be more experienced.


RE: I need help with the CodeIgniter routes... - albertleao - 11-20-2015

in routes:

PHP Code:
$route['produto/(:num)/(:any)'] = 'produto_controller/show/$1/$2'

in controller:

PHP Code:
public function show($id NULL$title NULL) {
  if(!empty($id)) {

  } elseif(!empty($this->input->get('id')) && !empty($this->input->get('title')) {

  }



Honestly though, you shouldn't need to search by the title if you have the ID.