Welcome Guest, Not a member yet? Register   Sign In
yet another seo url question

Hi again everyone,

I was wondering what are the options to pass an id without specifying it in the url.

So instead of this :


I would like to have :

or maybe:

but this one I guess is easy to achieve if I can pass the id not via the url.

So my question is what's the best practice to pass the id, without specifying it in the url.

I was thinking about session flashdata, but I am not sure if this is a good practice.

thanks all in advance and sorry for my bad english.

I am no expert but you could use (and therefore generate) a unique slug for the record you want to display, that would be your "seo-title" and retreive your record using it.


If you want to use the id then you could build it on your url as well as part of your "seo-title"


and use php to work it out.

Thanks a lot for your reply, the option with the id built in the url sounds great.. But actually I don't have any clue how can I work it out... I can't get it with regex because the title may contain also other numbers as my site is a classified type where people can add their own ads, therefore they can put numbers in the title.

So, I have a new question, how can I get the id from this type of urls :


Thanks in advance and sorry for my bad english

edit - simplified
// The method I have adopted is to use the seo-title:
I use a unique table field with SEO-TITLE and use SEO-TITLE.html.

The reason is that it is SEO friendly and any URL not found is used to search the table using "LIKE %...%"

1. route all other specific URLs
2. fall-through and route to a seo_controller/seo_method/seo-title
3. controller seo_method searches for seo-title
4. if found then get the data
otherwise remove dashes // str_replace('-', ' ', seo-title).
search for "seo title and all the other stuff"
5. display the page with the found or not-found data
$route["default_controller"] = "welcome";
$route["(:any)"]  = "seo_controller/seo_method/$1";


// Controller
  echo $this->uri->uri_string();
  echo $this->uri->segment(0);
  echo $this->uri->segment(1);
  echo $this->uri->segment(2);
  echo $this->uri->segment(3);
  echo $this->uri->segment(4);
  echo $this->uri->segment(5);

Take a look at:


Okay, your first question you stated you don't want to pass the ad id around in the URL, and then your first reply you said it was a good idea! LOL, not sure what you wanna do now! (eidt, opps, just re-read your reply comment, your were talking about combining the id and the seo slug together into one part of the uri, and then extracting the id later, I'd personally forget that option, too much mucking around, just have /controller/id/seoTitle or controller/seoTitle/id, or some such, it wont affect your 'google rankings' if you have an ID in there as it's own URI segment.)

- Anyway, forget using flash data, if someone does a page refresh you loose your data... not good!
- You could try using a session to store the ID, but then some people have cookies disabled (which is how CI stores session data by default, but you could set it up to be stored in a DB rather than a cookie, but thats another story, but could help you).
- Another option would be to do it all with forms and set the ID as a hidden field. So a person goes and views a bunch of Ads under the category Pet Supplies (for example). You echo out your ads, each one wrapped inside a form with the ID as a hidden field. Then use a button or image (or whatever) to 'action' that form (perhaps they click on it and it takes then to a detailed view of the ad, whatever it is). This will work, but the only problem with this is that SEARCH ENGINE SPIDERS cannot submit forms, and as such it will limit how much they will crawl your site. Perhaps this is an issue for your site, perhaps not, I'm not sure. But you can get around this problem (to some extent) with the use of an XML site map and/or a html site map in your footer. But again, that's another story.

Personally I'd just tack to ID somewhere in the URL. I do it with my forums and stuff, and it's not an issue for me. You just wouldn't want to do it for secure data (well duh!) like a User ID or some such.

Hope that helps a bit, let us know how your getting along with it!

You are right boltsabre, I am little bit confused too about this topic.
So let's take the following example.
If I keep the url like this :

if somebody changes the id segment, they will be redirected to the ad with that specific id and it will not care about the next uri segment.
I want to avoid somehow this situation.
In the following example :
if I concatenate the title with the id, the users will not tend to change it(hope so).
My main issue is that I don't know how to read that id from PHP point of view, let's say that is lack of knowledge.
The only thing which I have in mind right now, is to store the title + id as a slug into the db. And instead of searching by id, to search for the all string, but wouldn't be that a problem for mysql performance ?

Conclusion :
For the first case if I can avoid the situation of changing the id, It would be great.
For the second case, I need way to read from db by getting only the id from url, or to store that "slug" into the DB.

What would you recommend ?


Try storing url_title('Your Page title') as a unique field in your table and also using the result in your seo_title.


Details can be found here:


It will save you a lot of work and if the URL is not found then you can search on the parsed URL.

for example search on:
title LIKE "%Your%"
title LIKE "%page%"
title LIKE "%title%"

I know about url_title, but as I said above it will be a classified ads site, so it is a big possibility to have same title. I need a way to make them unique maybe to concatenate the title with the id, but I am sure about the mysql performance, because I will have lots of ads...

Hmmm, I'm at work and cannot check with my code/website (it's not online yet), but that's an interesting point about the user changing the id uri... it's actually been a while since I did any CI coding. But you should be able to check it yourself.

I'm pretty sure if a user changes the id uri segement, CI still loads through the controller/method/variable structure. What I'm trying to say is if a user does change the id, your controller should run again, which in turn will call the model to get the new 'seo-title-uri'... It shouldn't be a problem, just run your own quick test now! Let me know what happens. If we run into a problem we can look at some other options, otherwise problem solved!

Yeah, in my forum table i have these fields, if you don't have a structure like this you may want to consider doing a redesign:

id (int, primary key, auto increment)
seo-title (varchar)
title (varchar)
content (text)
date-posted (datetime)
...etc etc

My url structure is like this:

Where seo-title is just the normal title with every space and special character replaced with a dash - (and some extra coding to make sure i don't end up with seo-titles with multiple dashes like 'this---is--my-seo-title).

And i just query the db using uri->segement->2, that way your only searching a int field, not a id+seo-title field, thus keeping the db queries as speedy as possible!

Theme © iAndrew 2016 - Forum software by © MyBB