phpapiwebapishort-urltinyurl

How to shorten a url that contained "#" symbol by TinyURL api?


For example, I want to shorten this url: https://docs.python.org/3/library/subprocess.html#popen-constructor

I tried to pass https://docs.python.org/3/library/subprocess.html#popen-constructor as url parameter, but the returned url is actually shorten from https://docs.python.org/3/library/subprocess.html, so it won't jump to popen-constructor section.

Then I tried to pass https://docs.python.org/3/library/subprocess.html%23popen-constructor as url parameter, but the returned url doesn't work (404 not found).

The only solution is to use website of TinyURL it self, so I'm wondering if I can shorten a url that contained a "#" symbol by TinyURL api?


Solution

  • Note: due to stackoverflow security rules I can't add the tiny url. So in every examples bellow I have replace https://tinyurl.com by https://<tinyurl>.com

    You should encode whole target url, ie:

    https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fsubprocess.html%23popen-constructor
    

    Then, if you use api with the fully encode target url it will create a correct short link:

    https://<tinyurl>.com/api-create.php?url=https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fsubprocess.html%23popen-constructor
    

    result

    Tinyurl created (https://<tinyurl>.com/q3anmqb) will redirect to https://docs.python.org/3/library/subprocess.html#popen-constructor