How to rewrite url in codelgniter

2019-09-12 08:19发布

Hello First i tell all of you that in codelgniter framework i am new and i have a problem related to my url the url looks like this http://www.vacationplannersnetwork.com/search/name/france

but i want my URL looks like this http://www.vacationplannersnetwork.com/france

I do search engine optimization of this website so i want this type of structure ,so if anyone knows then please help me its highly recommended.thanks in advanced.

2条回答
趁早两清
2楼-- · 2019-09-12 08:57

It can be done over rerouteing. In your APPPATH . 'routes.php' file add this line:

$route['(:any)'] = 'search/name/$1';

Since you want to have first URI segment matching your results, you would need to add other specific routes before that one. For example:

$route['contact-us'] = 'public_controller/contact_method';
$route['aboout-us'] = 'public_controller/aboutus_method';
/*
 * other routes
 * here
 */
$route['(:any)'] = 'search/name/$1';

Docs.

Also, don't forget to change links anchor in view files if needed (for static pages/variables).

查看更多
迷人小祖宗
3楼-- · 2019-09-12 09:15

Just use

$route['france'] = 'search/name/france';

then in <a> should bee

<a href="<?php echo base_url()?>france
查看更多
登录 后发表回答