Welcome Guest, Not a member yet? Register   Sign In
Rewriting ID's to post names or item names
#1

[eluser]Coen de Jong[/eluser]
I like the fancy rewritten url's that CI is using, but would like to take this one step further.

Now, CI uses this:

/controller/method/id

This would mean that we get this kind of urls:

/ads/show/1128

Now, we want the ID replaced with the title of an ad, like this:

/ads/show/Manager_in_Seattle_with_lots_of_experience

Maybe even with .html or php attached to the end.

How can this be done with CI fairly delicate? Maybe with mod_rewrite even?
#2

[eluser]Dam1an[/eluser]
When you create the URL (eg anchor) you simple pass the paramter to be the name of the object, not the ID
The downside of this is the name needs to be unique (which is fine if you're using usernames)
You then just do a lookup in the database for that row
#3

[eluser]Coen de Jong[/eluser]
I know I can pass a value other than a number or ID, so that's not the point.

The point is that I would like to use the actual ID for DB lookup and the url to display the ads titles. That way I won't have to worry about duplicate ad titles.

Or would it be best to go with something like this:
/ads/show/1128/Manager_in_Seattle_with_lots_of_experience

In the end all that matters is the indexing by Google, so we won't be using that fourth segment, but it sits there being nice.
#4

[eluser]Dam1an[/eluser]
In which case you will have to use the ID as the parameter
Your solution of having the title as the next URI segment is the best way I think, it serves no purpose to the application but much nicer to look at, and more search engine friendly Smile




Theme © iAndrew 2016 - Forum software by © MyBB