I have my CI site working well except the URL's are a bit ugly. What approach should I take to enable me to ro开发者_开发问答ute what is displaying at:
http://domain.com/content/index/6/Planning
to the url:
http://domain.com/Planning
I'm confused about whether this should be be done in the routes file or in my .htaccess
Thanks
There are couple of ways to set up config/routes.php, the suitability depends on your requirements.
Route for each page, if you have just a couple of pages that you want to route:
$route['Planning'] = 'content/index/6'; $route['Working'] = 'content/index/7'; // etc.
You can use fallback url, that will match after all other route rules - that means you must set rules that might match this rule before the fallback rule. It also means you loose ID, and have to query database based on the title:
$route['register'] = 'register'; // this would match the fallback rule $route['([a-z-A-Z1-9_]+)'] = 'content/index/$1'; // letters, numbers and underscore // you'll receive "Planning" as parameter to Content::index method
Or you can have policy that all urls to content must start with capital letter, in that case you don't have to worry about other route rules
$route['([A-Z]{1}[a-z-A-Z1-9_]+)'] = 'content/index/$1'; // again, you'll receive "Planning" as parameter to Content::index method
You still want the numerical ID, so you don't have to change the controller/model:
$route['(\d+)/[a-z-A-Z1-9_]+'] = 'content/index/$1'; // routes now look uglier: http://domain.com/6/Planning
http://codeigniter.com/user_guide/general/routing.html
you should be able to accomplish that with some of the examples on this page
精彩评论