Custom Routing for SEO friendly URLs - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Custom Routing for SEO friendly URLs (/showthread.php?tid=63456) |
Custom Routing for SEO friendly URLs - armadillo - 11-01-2015 I am having a routing problem that i don't understand , i'm following whats on the documentation, perhaps im not fully understanding how these routes work, here is the issue, i have an articles Controller which makes use of view_by_slug method, this just grabs a field from the database that instead of having : http://localhost/kewlcms/articles/view/1 in the URLs i have this: http://localhost/kewlcms/articles/view_by_slug/first-article http://localhost/kewlcms/articles/view_by_slug/second-article .. . This is the snippet i have on the home page that creates a list of the most recent posts, as you can see it uses view_by_slug/<?php echo $article->slug; ?> on home.php PHP Code: <ul class="row marketing"> But i would like to change these URLs: http://localhost/kewlcms/articles/view_by_slug/first-article instead of articles/view_by_slug/first-article i would like to change it to : http://localhost/kewlcms/articles/first-article or http://localhost/kewlcms/blog/first-article This is what i have on routes.php, i am including the 2 lines which are the ones i tried so far but im getting 404 not found errors PHP Code: $route['articles/view_by_slug/(:any)'] = 'articles/$1' ; RE: Custom Routing for SEO friendly URLs - skunkbad - 11-01-2015 Is kewlcms your controller, or your install dir? RE: Custom Routing for SEO friendly URLs - armadillo - 11-02-2015 (11-01-2015, 09:18 PM)skunkbad Wrote: Is kewlcms your controller, or your install dir? It's the install dir, i have several subfolders under localhost RE: Custom Routing for SEO friendly URLs - arma7x - 11-02-2015 Remove line $route['articles/view_by_slug/(:any)'] ='articles/$1': RE: Custom Routing for SEO friendly URLs - Avenirer - 11-03-2015 Did you try using _remap()? http://www.codeigniter.com/user_guide/general/controllers.html#remapping-method-calls You can redirect every request to index() so that will serve another method. RE: Custom Routing for SEO friendly URLs - armadillo - 11-03-2015 (11-02-2015, 12:16 AM)arma7x Wrote: Remove line $route['articles/view_by_slug/(:any)'] ='articles/$1': That didn't work, don't know why i tried what the documentation says but still can't get it to work properly RE: Custom Routing for SEO friendly URLs - arma7x - 11-03-2015 I think the problem is your URI http://localhost/kewlcms/articles/view_by_slug/first-article. 'kewlcms' is always the first segment of your URI. Fire up your apps using PHP built-in webserver with option -t which is your document root, in your case, kewlcms directory. |