Welcome Guest, Not a member yet? Register   Sign In
url shortening and clean urls
#1

[eluser]rickyracoon[/eluser]
I am working on a site that has a table in the database that stores links to some external articles, with the columns link_id, url, and title.

My urls currently look like:

http://www.site.com/article/324

I'd like to change it so the urls will look like:

http://www.site.com/article-title-dash-separated

..and also provide a short-url version of the link that does not include the link_id but rather is just a random hash:

http://www.site.com/F5ytK (example)

How would I route requests to appropriate controllers since everything is just at the top level? I still need other areas of the site to route properly, such as:

http://www.site.com/about

Should route to the about controller. But what if an article has the title "about"? Or what if an article title ends up being the same as the short-url hash?

How would I prevent collisions? What are the best practices here? I'd appreciate any suggestions.
#2

[eluser]kkristo[/eluser]
http://www.site.com/article/article-titl...-separated

And add article table extra field where store article-title-dash-separated.

But I think not bad: http://www.site.com/article/show/123/art...-separated

Then you can use int field , what is faster than char (for search). Or if you have lot articles, then add month/year/id/name-dash

This "dash-separated" name for google SEO. Trust me.. no on write full url Smile www.mysite.com/this-funny-article-that-do-somthing Wink
#3

[eluser]intractve[/eluser]
Having a controller called article (http://yoursite.com/article/123/dash-sep...icle-title) is not bad in terms of SEO, it will give you equal ranking in SEO when used properly with sitemaps. So I would go with that in terms of speed in accessing your database entries. Doing Full Text searches is server intensive.

use the id to reference the article, and have the url helper, url_title() make dashed titles for you and save it in the db.

For Short Permalinks, you can checkout bit.ly API
http://code.google.com/p/bitly-api/wiki/...umentation

If you use this, You should shorten links and save it in your DB when the article is created and saved so that you dont make multiple links pointing to same article.
Advantage using this is that you can track usage statistics of your short links in bit.ly
#4

[eluser]rickyracoon[/eluser]
I get the point about using the numeric id to look up the articles, but its an auto-increment field and I don't like the underlying id exposed. Also, I hate that the text in the segment following the id is arbitrary - makes me worry about duplicate content in SEO. For example:

http://yoursite.com/article/123/real-article-title

would be the same as if someone linked to it using:

http://yoursite.com/article/123/doesnt-m...-goes-here

To prevent the title part of the URL from being invalid I'd have to lookup the DB anyway, which is why I figured I might as well drop the id altogether. Any thoughts on that?

Also, thanks for the bitly API - but I'm afraid the customer wants the site to act as their own internal URL shortener (intranet site) so I still don't understand how I can differentiate between the "short url hash" and other controller names. Is there a certain reg expression that might work with routes? Or is there a way for to do routing after all controller names are checked for?
#5

[eluser]kkristo[/eluser]
You can do it controller:

if (url_title($this->uri->segment(3)) != url_title($this->data['RealName'])){
redirect( base_url().'article/show/123/'.url_title($this->data['RealName']) ,'location', '301');
}




Theme © iAndrew 2016 - Forum software by © MyBB