CodeIgniter Forums

Full Version: SEO Friendly url (still get id from address bar, but display data name)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]artlover[/eluser]
Hi friends,

I'm building my first project with Codeigniter. I love it, I enjoy so much Smile
I have an issue about SEO friendly url.

my current url:
domain.com/client/43

I get id from address bar to get client details from db. any chance to change url like;
domain.com/client/blabla-company-bla

and still get my data from db somehow?

thanks a lot!!

El Forum

[eluser]Dam1an[/eluser]
Assuming you can gaurantee each client name will be unique, yes
If not, you could always do
domain.com/client/client-name-goes-here/123

El Forum

[eluser]artlover[/eluser]
[quote author="Dam1an" date="1248981219"]Assuming you can gaurantee each client name will be unique, yes
If not, you could always do
domain.com/client/client-name-goes-here/123[/quote]

thanks for answer : )

client names are unique. but at your example, i still depend on id (/123). i need to reach the page with type of url domain.com/client/client-name

El Forum

[eluser]artlover[/eluser]
if I use like
domain.com/client/client-name

does it mean, I will have to get data from db with client name, not with id?

El Forum

[eluser]Dam1an[/eluser]
yeah, you should just need to change the query in your model to use client name instead of id in the where clause Smile

El Forum

[eluser]artlover[/eluser]
[quote author="Dam1an" date="1248981706"]yeah, you should just need to change the query in your model to use client name instead of id in the where clause Smile[/quote]

so I will have to replace the - at adressbar url with space for matching with the db client name. or is there any cool trick at CI for that? : )

El Forum

[eluser]Phil Sturgeon[/eluser]
Add an extra 'slug' field which should be a UNIQUE key in the SQL. When you create the item store a version of the title using url_title() then match the slug in the URL against the one in the DB.

El Forum

[eluser]artlover[/eluser]
[quote author="Phil Sturgeon" date="1248982405"]Add an extra 'slug' field which should be a UNIQUE key in the SQL. When you create the item store a version of the title using url_title() then match the slug in the URL against the one in the DB.[/quote]

Thanks Phil,
do you mean generating a unique key from record title? sorry I'm a bit confused of your way. : /