Home > Web Development > “Tinyurl”-ify DropBox Public Links With .htaccess

“Tinyurl”-ify DropBox Public Links With .htaccess

I just recently started using DropBox on Ubuntu 8.10 “Intrepid Ibex” and leftyfb in IRC pointed out to me a nifty little trick with .htaccess files.  If you’ve been using DropBox I’m sure you’ve seen or made use of the Public folder and sharing files.  You may have also noticed that the DropBox Public links are long and likely hard to remember when needed.

One thing that you can do, if you have your own web server, is dynamically generate these public links.  For example:

Original DropBox Public URL:

http://dl.getdropbox.com/u/312414/Christer_Edwards.asc

DropBox Public URL with .htaccess trick:

http://zelut.org/dropbox/Christer_Edwards.asc

In order to accomplish this you’ll need access to a webserver and the ability to create and use a .htaccess file.  On my webserver I created a folder called “dropbox” and then pasted the following into a new file, .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://dl.getdropbox.com/u/012345/$1 [L,QSA]

You will need to replace the “012345″ with your unique ID.  As you notice from the original link above, my unique ID is “312414″.  You can find yours by copying the public link within Nautilus.

Once this is done you can share files by placing them into your DropBox Public folder and then appending the filename to your webserver URL + created folder.  Again, since I created the folder “dropbox” on http://zelut.org/, my url is http://zelut.org/dropbox/.  I simply append the filename I want to share and its done!

If anyone can suggest a way to present this URL with an index.html that may be a cool trick.

If this article has been helpful, please consider linking to it.

Categories: Web Development Tags: ,

Related Posts

  1. November 8th, 2008 at 11:33 | #1

    Is it working yet? I couldn’t find my USER ID…

  2. November 8th, 2008 at 13:46 | #2

    @Vinicius – if you right-click a file within Dropbox/Public and select Dropbox > Copy Public Link, you can then paste that link anywhere. The userID you’re looking for is the 6 digits just after /u/.

  3. November 9th, 2008 at 10:59 | #3

    This is great :) .

  4. January 20th, 2009 at 15:33 | #4

    What about one more line?

    RewriteRule ^index\.html$ http://dl.getdropbox.com/u/012345/index.html [L]

    Just check to have an index.html file into your public folder in dropbox; seems to work fine here.

    Ciao, f.

  5. Pet
    January 23rd, 2010 at 12:40 | #5

    Great Tip.

    I have a question if I follow your .htaccess trick will my server download the file first from dropbox and then stream it to the user?

    The reason I’m asking is because I have pretty heavy files on my public folder and I do not want to have to pay for additional bandwidth.

    Chers,

    Pet

    • January 23rd, 2010 at 12:50 | #6

      Pet – your server won’t download anything from Dropbox. All it is doing is abstracting the URL to something more manageable and forwarding the user directly to the Dropbox share.