-1

I am trying to redirect a Short Url to another Url, For a better understanding

Consider https://get.vine.co if we paste this on the Desktop Browser we will be redirect to http://www.windowsphone.com/en-us/store/app/vine/f9e6f07e-e47e-47f5-806d-55d4f79f2b60

In the same way if the same Short Url is called on Mobile device it redirects to Play store or Apple Store.

How Can I achieve this using Codeigniter and PHP.

I assume this is not an anchor tag redirection!!

NOTE: And i am looking for user defined short url.. Which must look like "https://get.mysite.co"

Kindly put me in some right direction?

Ramaraju.d
  • 1,301
  • 6
  • 26
  • 46
  • You have to look for the user-agent of the client (http://mobiledetect.net/). That determines the type of user. Next, you will send a redirect header based upon the previously determined user type (https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html - redirect) – Tom Sep 09 '14 at 07:15
  • I haven't own a Short Url. Thank you @TomLankhorst I will check this. – Ramaraju.d Sep 09 '14 at 07:20
  • Then you should use a redirect service (https://developers.google.com/url-shortener/) that redirect to a PHP script that does the above. ;) – Tom Sep 09 '14 at 07:22
  • Thank you so much @TomLankhorst. Yes I have idea on handling the User agent etc.. The actual part is Short Url.. Thank for the link. – Ramaraju.d Sep 09 '14 at 07:26
  • I want to create a similar url example https://get.mysite.co I dont want google to assign some string – Ramaraju.d Sep 09 '14 at 08:56

1 Answers1

0

I don't know much about codeigniter but in theory you'd have to store the original url along with your short-url hash. Then on a request with that hash you'd have to lookup that hash in DB and simple do a Location header to the original url. You could use http://www.hashids.org/ to translate between an auto-increment in your db to a short hash back and forth. That would make your table design a breeze.

Anticom
  • 975
  • 13
  • 29
  • Thanks for the reply @Antocom.. But Is is that necessary to save them in DB? – Ramaraju.d Sep 09 '14 at 08:59
  • You could try some fancy compression but IMHO this won't get you anywhere. I'd recommend using the hashids lib with a simple 2-col table: id and url and leverage the hashids-lib to translate between the id and the has you want to use in your short url. – Anticom Sep 09 '14 at 10:43