简体   繁体   中英

CodeIgniter Change URL Routes

I have a Real Estate Site, in CodeIgniter my link names is:

htp://examplesite(dot)com/property/31/en/property_title

I want to replace it with:

htp://examplesite(dot)com/my-custom-slug.htm

or

htp://examplesite(dot)com/property_title

Both ways might be ok. My routes are:

$route['default_controller'] = "frontend";
$route['404_override'] = 'frontend';

/* Custom routing */
$route['admin'] = 'admin/dashboard';
//$route['secret'] = 'admin/dashboard';

// To change property->listing in uri
$route['listing/(:num)/(:any)/(:any)'] = "property/$1/$2/$3";
$route['listing/(:num)/(:any)'] = "property/$1/$2";

what is the best way in this case?

I know there is a possible solution that:

Add

$config['listing_uri'] = 'listing';

Than add to:

In 'application\\config\\routes.php'

After:

$route['listing/(:num)/(:any)/(:any)'] = "property/$1/$2/$3";
$route['listing/(:num)/(:any)'] = "property/$1/$2";

Add also:

$route['changed/(:num)/(:any)/(:any)'] = "property/$1/$2/$3";
$route['changed/(:num)/(:any)'] = "property/$1/$2";

but is there any way to remove the 'listing', to see only the clean url (for better seo purpose) ??

Welcome, luckily your problem isn't too big :)

Maybe have one slug before the property title to make the solution a bit more scalable:

$route["listing/(:any)"] = "property/view/$1";

Then point your browser to yoursite.com/listing/some_slug or yoursite.com/listing/12

You will need to have a slug associated with each property, otherwise you can use the id, and in the view function just retrieve the property based on the slug or id parameter.

If you don't want to include the listing/ you might have problems down the line when trying to create other routes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM