I'm not sure when they really utilizing a RewriteRule (Apache mod_rewrite) with this, but when we append an URL following the Link to bit.ly (ie: http://bit.ly/http://www.somesite.com/), it requires the URL appended like a parameter (http://bit.ly/?u=http%3A%2F%2Fwww.somesite.com%2F).

Someone understands how to do this, maybe having a RewriteRule or something like that else? If that's the case, what could possibly be the regex to handle this?


I'd imagine their rewrite rule looks something similar to this:

 RewriteRule ^(http.*)$ ?u=$1?%{QUERY_STRING} [R]

Could not help but fiddle around with this particular: Accepts multiple methods and eliminates appending the ? if there's no query string:

   RewriteCond %{QUERY_STRING} (^$)
   RewriteRule ^((http|ftp).*)$ ?u=$1 [B,R,L]

   RewriteRule ^((http|ftp).*)$ ?u=$1?%{QUERY_STRING} [B,R,L]

It's most likely something during these lines:

<IfModule mod_rewrite.c>
    RewriteRule ^(.*)$ index.php?/$1 [L]

After which have index.php perform a:

  1. search database to ascertain if link is alright or flagged (badware, junk e-mail, etc)
  2. mark visit in stats database
  3. throw http 301 headers around the user for any proper redirect