Skip to content

Instantly share code, notes, and snippets.

@kolber
Created June 24, 2010 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolber/451040 to your computer and use it in GitHub Desktop.
Save kolber/451040 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/http'
def validate(url)
uri = URI.parse(url)
response = Net::HTTP.get_response(uri)
case response
when Net::HTTPSuccess
return uri
when Net::HTTPRedirection
return 'redirected: '+response['location']
else
return nil
end
end
#puts validate('http://germanforblack.com') # redirects
puts validate('http://germanforblack.com') # doesn't redirect
@benschwarz
Copy link

FYI, my site will redirect www to the root of the domain. Not sure why you chose me though.

@kolber
Copy link
Author

kolber commented Jun 24, 2010

Ah, yea, that second URL was meant to read http://www.germanforblack.com.
I knew your site was using www redirection, so it popped into my head as a test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment