Welcome Guest, Not a member yet? Register   Sign In
need to get id but show name in url to make it friendly for seo
#1

[eluser]the_unforgiven[/eluser]
How does one get the id of a db item but then show it has the name in the URL?


so at the moment i have: localhost/home/categories/2

but want it to get the id but look like this: localhost/home/categories/my-product

the words my-product is the path_url in the db
#2

[eluser]CroNiX[/eluser]
When creating the anchors, use the 'path_url' as the last segment instead of the id.

Then in your controllers, 'my-product' would be url segment 3, and then just search the db field 'path_url' for it (instead of the id).
#3

[eluser]LuckyFella73[/eluser]
I would do one db query allready when building
that link:
Code:
// db query
// get path_url for $id=whatever
// $path url = ...

// then build link with that value:
echo '<a href="'.base_url().'home/categories/'.$id.'/'.$path url.'">txt</a>';

When it comes to the method "categories" it*s up
to you if you do something with the 3rd url segment.
You can just ignore it in that case.
#4

[eluser]the_unforgiven[/eluser]
Ok thats great cheers
#5

[eluser]emily12[/eluser]
As a special bonus, I would add the $id right before or after the url. So /categories/mypage-16 where 16 is the article id.

You should have a validation setup so that it checks whether this exists or not during submission. Search engines don't seem to care about numbers at the end of a url but they do tend to care at least from my understanding when you have mypage-16 and mypage-17. They will treat it in the same group even if they are entirely different. Who knows how Google works, maybe they are smarter than that lol

It's up to you, and I hope this little tip was useful and prevents any problems in the future. Smile
#6

[eluser]boltsabre[/eluser]
I really wouldn't worry about it too much. One of the latest google updates is now checking for "over optimisation", so if you have a spammy url segment like "this-is-my-product-it-is-red" you could start flags waving in googles ranking algo. If it was JUST that you should be fine, but if you have your product name multiple times in your text content, navigation, image alt text, title text, css class names, etc, you could be in for a rough ride.




Theme © iAndrew 2016 - Forum software by © MyBB