CodeIgniter Forums
SEO friendly urls http://example.com/mymethod,name_of_article,2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: SEO friendly urls http://example.com/mymethod,name_of_article,2 (/showthread.php?tid=57241)



SEO friendly urls http://example.com/mymethod,name_of_article,2 - El Forum - 02-28-2013

[eluser]jacobson[/eluser]
Hello I wanted to create more friendly urls for my CI application with a structure : http://example.com/mymethod,name_of_article,2. How can I make my app to examine URL like this and take it's 1'st parameter as method in the controller, second as the name of article (for SEO) and last - article ID.

Thx for help


SEO friendly urls http://example.com/mymethod,name_of_article,2 - El Forum - 02-28-2013

[eluser]ravengerpl[/eluser]
For example your method is named "post" and controller "blog". To get urls like
Code:
mysite.com/posts,name,id
:

routes.php
Code:
$route['posts,(:any),(:num)'] = "blog/post/$1/$2"

blog.php
Code:
public function post($name, $id)
{
$data['post'] = $this->post_model->get_post($name, $id);
}

post_model.php
Code:
public function get_post($name, $id)
{
$query = $this->db->get_where('post_table', array('post_name' => $name, 'post_id' => $id));
return $query->row_array();
}

There may be typos somewhere but hope you get the idea. Remember to add some error handling (when you deleted post from database and someone clicked on old link etc.).


SEO friendly urls http://example.com/mymethod,name_of_article,2 - El Forum - 02-28-2013

[eluser]jacobson[/eluser]
Yup i think ill make it that way. The title of the post won't be used in queries, just the id Smile but anyway thanks for help.