Welcome Guest, Not a member yet? Register   Sign In
.htaccess rewrite for SEO - Question
#1

[eluser]Deep Arora[/eluser]
Hi - CI is a wonderful thing and has worked beautifully for my needs. I was able to develop the frontend of my CMS in just 4 days. I am still working on it, but I got a question -

I am not familiar with .htaccess a lot. I have used what CI has suggested to remove the index.php part. As a result, I have this a my link structure for the blog where I have installed the beta version:

http://littledumbguy.com/blog/post/9

Now, in the admin panel, I use a SEO TITLE for every post which is something like this "this-is-a-post". How can I make the URLs such that instead of:

http://littledumbguy.com/blog/post/9

they become..

http://littledumbguy.com/blog/this-is-a-post

or even better..

http://littledumbguy.com/9/this-is-a-post

where 9 is the post id number

Thanks.
Deep
#2

[eluser]Dam1an[/eluser]
You would use routes to direct anything which is number/string to go to blog/post/id (You don't need to route the title)

To have the title in the URL, just add it to the URLs like so
Code:
<?=anchor($post->id.'/'.$post->title, $post->title)?>

You would obviously need to replace spaces with underscores etc in the anchor
#3

[eluser]Michael Wales[/eluser]
I prefer example.com/this-is-my-title or example.com/category/this-is-my-title for SEO purposes.

Code:
// Catch example.com/category/this-is-my-title
$route['([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)'] = 'blog/post/$1';
// Catch example.com/category
$route['([a-zA-Z0-9-]+)'] = 'blog/category/$1';

Code:
<?php echo anchor(url_title($category, 'dash', TRUE) . '/' . url_title($title, 'dash', TRUE), $title);

Code:
function post($title_slug = NULL) {
  if ($title_slug === NULL) {
    // If the user somehow got here w/o having a slug
    // send them to the homepage
    redirect();
  }

  // Load the post from database using the unique slug
  // If num_rows() === 0, throw a 404
  // Else, Display view
}
#4

[eluser]Dam1an[/eluser]
If you do it as Michael suggested, you need to make sure you don't have any duplicate page title, either make sure every one is unique (and if not, make the user change it) or when adding a page, check, and if that one already exists, then just append _2 (or _3 etc) to make sure its unique
#5

[eluser]Michael Wales[/eluser]
Yeah - you'll also have to catch any other controllers you have before the "catch-alls" for the category/post. For instance:

Code:
$route['contact'] = 'contact';

And then, make sure you don't allow the user to create a category named contact.
#6

[eluser]Deep Arora[/eluser]
Awesome. I will try that now and post how it worked.

Quick question - does this mean we don't require editing .htacces at all?
#7

[eluser]Deep Arora[/eluser]
I got it working now..I have used this structure:

http://littledumbguy.com/blog/9/why-i-mo...press.html

Reason is that I use 4 types of posts, blog, video, pages, and downloads. If I use catch all, I'm not if I can redirect to proper destination.

But what is your take? Is this URL structure good for SEO?
#8

[eluser]NachoF[/eluser]
the thing is whatever I write in the third segment will work.
#9

[eluser]Deep Arora[/eluser]
bummer...is there a way to stop this, or is it ok to let it be like this..?
#10

[eluser]NachoF[/eluser]
Michael Wales approach
Code:
example.com/this-is-my-title




Theme © iAndrew 2016 - Forum software by © MyBB