CodeIgniter Forums
yet another seo url question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: yet another seo url question (/thread-43891.html)

Pages: 1 2


yet another seo url question - El Forum - 07-27-2011

[eluser]StefanAlexandru[/eluser]
Hi again everyone,

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

So instead of this :

Code:
http://www.mydomain.com/controller/id/seo-title

I would like to have :
Code:
http://www.mydomain.com/controller/seo-title

or maybe:
Code:
http://www.mydomain.com/seo-title

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.


yet another seo url question - El Forum - 07-27-2011

[eluser]Madoc[/eluser]
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.

Code:
http://www.mydomain.com/controller/function/seo-title-as-unique-slug

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

Code:
http://www.mydomain.com/controller/function/id-seo-title
or
Code:
http://www.mydomain.com/controller/function/seo-title-id

and use php to work it out.


yet another seo url question - El Forum - 07-27-2011

[eluser]StefanAlexandru[/eluser]
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 :

Code:
http://www.mydomain.com/controller/function/seo-title-id


Thanks in advance and sorry for my bad english


yet another seo url question - El Forum - 07-27-2011

[eluser]John_Betong_002[/eluser]
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
 
 
./application/config/route/php
Code:
$route["default_controller"] = "welcome";
  ...
  ...
$route["(:any)"]  = "seo_controller/seo_method/$1";
 
 

Also...
Code:
http://www.mydomain.com/controller/function/seo-title-id

// 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:

http://ellislab.com/codeigniter/user-guide/libraries/uri.html
 
 


yet another seo url question - El Forum - 07-27-2011

[eluser]boltsabre[/eluser]
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!


yet another seo url question - El Forum - 07-27-2011

[eluser]StefanAlexandru[/eluser]
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 :
Code:
http://www.mydomain.com/controller/id/seo-title

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 :
Code:
http://www.mydomain.com/controller/function/seo-title-id
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 ?


Thanks


yet another seo url question - El Forum - 07-27-2011

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

http://example.com/Your-page-title.html

Details can be found here:

http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

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:
Code:
title LIKE "%Your%"
  OR
title LIKE "%page%"
  OR
title LIKE "%title%"
 
 


yet another seo url question - El Forum - 07-27-2011

[eluser]StefanAlexandru[/eluser]
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...


yet another seo url question - El Forum - 07-27-2011

[eluser]boltsabre[/eluser]
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!


yet another seo url question - El Forum - 07-27-2011

[eluser]boltsabre[/eluser]
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:
myDomain.com/forum/id/seo-title

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!