Rails: How to create an url shortener? -
i'm not sure if url shortener
right name it, because of search results point toward things bit.ly
.
so, here want: given url strings like:
http://avc.com http://firstround.com/review/feed/ http://svpg.com/articles/ http://www.medium.com/ http://www.paulgraham.com/
turn
avc.com firstround.com svpg.com medium.com paulgraham.com
no subdomain, no subdirectory, no /
.
i can url.split('://')[1].split('/')[0]
, cannot rid of www
, , i'm wondering if there better way of doing it?
you can use uri module , use regexp parse out first www. like
def host(url) uri = uri.parse(url) uri.host.sub(/^www./, '') end
Comments
Post a Comment