Skip to content

Instantly share code, notes, and snippets.

@taylorwood
Created June 21, 2019 19:35
Show Gist options
  • Save taylorwood/fa4464d1350884291dbdd7ede7dea40f to your computer and use it in GitHub Desktop.
Save taylorwood/fa4464d1350884291dbdd7ede7dea40f to your computer and use it in GitHub Desktop.
Google Redirect (Beta)

Google Redirect (Beta)

Google has a https://www.google.com/url?q= endpoint that redirects to q, and it turns out you can nest these recursively and it'll 302 redirect you to each one in succession.

So here's the the most inefficient link to Google that will fit in a Tweet:

https://www.google.com/url?q=https%3A%2F%2Fwww.google.com%2Furl%3Fq%3Dhttps%253A%252F%252Fwww.google.com%252Furl%253Fq%253Dhttps%25253A%25252F%25252Fwww.google.com%25252Furl%25253Fq%25253Dhttps%2525253A%2525252F%2525252Fwww.google.com

Here's some Clojure I used to make the link:

(def url "https://www.google.com")
(defn redirect [s]
  (str url "/url?q=" (java.net.URLEncoder/encode s)))
(->> (iterate redirect url)
     (take-while #(<= (count %) 280))
     (last))
=> "https://www.google.com/url?q=https%3A%2F%2Fwww.google.com%2Furl%3Fq%3Dhttps%253A%252F%252Fwww.google.com%252Furl%253Fq%253Dhttps%25253A%25252F%25252Fwww.google.com%25252Furl%25253Fq%25253Dhttps%2525253A%2525252F%2525252Fwww.google.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment