SEO implement? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: SEO implement? (/showthread.php?tid=29952) |
SEO implement? - El Forum - 04-27-2010 [eluser]Iwasignited[/eluser] Hi everyone, I have a question related to SEO. I want to turn my url from 'post/view/1' to 'post/view/title-of-the-first-post', I created a column called alias in my post table but I'm not sure what to do next. Please help me. Thanks. Best regards SEO implement? - El Forum - 04-27-2010 [eluser]Stuey[/eluser] I'm currently very new to all of this and have been tinkering with the very same approach to my own little blog. I've basically taken the approach of setting up a route in config/routes.php that goes something along the lines of: Code: $route['blog/(:num)'] = "blog/view/$1"; Then in my controller I have this: Code: function view($post_id=null,$sef_url="") Basically my URI structure contains the post ID, so that you could enter "/blog/view/123/whatever-slug-line-i-want" and it would still go to the correct article. If the slug/SEO friendly URL (sef_url in my case) doesn't match, it redirects to the correct post anyway. You could replace the ID in my example with a alias lookup. Probably could be done better than this, but I'm still learning. Hope that helps. SEO implement? - El Forum - 04-27-2010 [eluser]Iwasignited[/eluser] that definitely helps. Thank you again SEO implement? - El Forum - 04-27-2010 [eluser]pickupman[/eluser] Taking the idea from Phil Sturgeon's PyroCMS and similar feature in Wordpress, is create a slug field. When I create a new article, I have the slug auto generated from the title of the post. I check the DB if slug already exists when saving the page. Then I use the route Code: $routes['blog/(:any)'] = 'blog/view/$1'; Then in my blog/post method I first lookup the slug parameter in the DB, and if nothing is returned I check for a post id. If that fails, I just load the default "home" slug. SEO implement? - El Forum - 04-27-2010 [eluser]paulc010[/eluser] A method I've used for news stories (never going to be that many of them, so the limitations are acceptable): Code: function post($uri = 1) The 'slug' in the post table has to be unique, so you would need to enforce that..... Paul SEO implement? - El Forum - 04-27-2010 [eluser]pickupman[/eluser] Code: redirect(base_url().'news/post/'.$slug, 'location', 301); Probably should be: Code: redirect(site_url('news/post/'.$slug), 'location', 301); In case you ever change enable/disable index.php moving files to different server configs, site_url() works better, as it figures out whether you have a index.php or not. SEO implement? - El Forum - 04-27-2010 [eluser]Stuey[/eluser] [quote author="Iwasignited" date="1272394230"]that definitely helps. Thank you again[/quote] Thinking back, it was one of Phil's posts where I got that code I think. I found it useful to keep the post/article ID in the URL (just before the slug URI) so that if someone mistyped the slug when referring/linking it would still serve up the correct article as well as allowing duplicate slugs (not that such things would happen often tho). Paul's approach is good also, keeps it simple and logical imo. |