본문 바로가기
Dev.Stuff

짧게 줄인 URL의 실제 URL 확인 원리 및 방법 (How to know original URL of shortened URL)

by Devkin 2012. 6. 27.

트위터의 제한된 글자수로 인해 짧은 URL 사용이 대중화되었다. 장점은 당연히 바이트수를 줄일수 있다는 거고, 단점이라 한다면 해당 URL 이 어디를 가르킬지 URL 만 봐서는 알수가 없다는 거다. 오리지널 URL을 확인해 볼 수 있는 사이트나 플러그인의 확인 원리 및 제공 서비스들에 대해 알아보자.


짧은 URL 의 실제 URL 확인 원리


짧게 줄인 해당 링크를 클릭했을 때 발생하는 GET Request 의 Response 로, 'HTTP 30x' 가 리턴되고 'Location :' 헤더에 실제 URL 정보가 표시된다. 따라서, Body 전체를 Response 할 필요없이, HTTP HEADER Request 를 지원하는 curl 등을 이용하여 PHP 나 Javascript 에서 리턴된 헤더의 'Location' 정보만 파싱하여 표시해주면 불필요한 리소스 사용을 줄일 수 있다. 다음은 주로 사용하는 Short URL 서비스의 Request/Response 과정을 캡쳐한 내용이다.


bit.ly

GET /Ac6FG6 HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: ko-KR
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: bit.ly
Connection: Keep-Alive
Cookie: _bit=4fde5237-00126-06293-421cf10a

HTTP/1.1 301 Moved
Server: nginx
Date: Tue, 26 Jun 2012 17:13:49 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Cache-control: private; max-age=90
Location: http://nachbaur.com/blog/core-graphics-isnt-scary-honest
MIME-Version: 1.0
Content-Length: 148

goo.gl

GET /bX8EK HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: ko-KR
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: goo.gl
Connection: Keep-Alive

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 26 Jun 2012 18:12:56 GMT
Location: http://developer.samsung.com/developerBlogView.do?board_id=487&pageSize=10&pageNum=1&orderby=&blogeh=E&sctype=&syear=&stag=
Content-Encoding: gzip
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 251
Server: GSE

durl.me

GET /2my7mc HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: ko-KR
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: durl.me
Connection: Keep-Alive

HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: http://metalkin.tistory.com/49
Content-Length: 0
Date: Tue, 26 Jun 2012 18:16:26 GMT

me2.do

GET /GoZMQjg HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: ko-KR
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: me2.do
Connection: Keep-Alive

HTTP/1.1 301 Moved Permanently
Date: Tue, 26 Jun 2012 18:14:58 GMT
Server: Apache
Pragma: No-cache
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Location: http://helloworld.naver.com/helloworld/70808
Content-Length: 0
Connection: close
Content-Type: text/html;charset=UTF-8

 SERVICE

CODE 

DESCRIPTION 

SERVER 

 bit.ly

 301

 Moved  nginx

 goo.gl

 301

 Moved Permanently

 GSE

 durl.me

 302

 Moved Temporarily

 Apache-Coyote

 me2.do

 301

 Moved Permanently  Apache


Short URL 확인 웹사이트

PHP Source Code
Chrome Extension

관련글

반응형

댓글