Finding the final url of a redirect

In one of my websites there was a complicated mechanism for redirecting mobile users from desktop pages to their mobile versions.  When I needed to get the mobile final url in order to use it in my rel=”alternate” links I used a starting url and followed the redirects until getting the final url.

Here is the code I used:

 

Leave a Reply

Your email address will not be published. Required fields are marked *