• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

A file as a directory

I want to provide my users with an easy URL that connects them to a specific file.

What I've got in mind would be something like "http://www.myserver.com/their_id_number."

So, if the URL, using the format I'm envisioning, looked like this: http://www.brucegust.com/12345 then it would direct the user to the appropriate page where I'm grabbing the id number and doing the necessary coding to provide them with the info I want to communicate.

I've got over 60,000 ids, so that number of folders isn't practical, but it seems I've seen what I'm trying to do. My question is: How? How do you set up your server in such a way where you have the capacity to do what I'm attempting?

3 Solutions
I would create a 2 level tree:
a. 1st level with 600 folders,
b. 2nd level with 100 folders,

The total will be 600*100=60,000 ids.
No problem, I've done this with a system that carried well over 2 million IDs. The solution is to use URL rewriting to look for URLs that have a specific format to them, like:


Then rewrite those URLs and redirect the request to a single PHP script (a quiet redirect so that the user doesn't see the URL change). That PHP script can then parse the URL and extract the ID, and present the data that is applicable for that ID.

Here's my article on using .htaccess to set up URL rewrites:

I would also strongly consider using more than one ID. Have a "check" value that corresponds to the ID so that a malicious user can't just try each ID, one at a time, and extract data from your system that does not belong to them.
To extend what gr8gonzo said:

Connecting user content with an exposed id like that looks like it could be a real security problem.  You will need to have some kind of authentication to protect user information.

brucegustPHP DeveloperAuthor Commented:
What I'll do is use a hex key to prevent ids from being exposed, but now, here's my question:

I'll turn on the Rewrite Engine, but then how do I configure it so it only kicks on when there's an id? My concern is that the way I have it in my head right now, any valid address after the slash is going to be processed as a rewrite and I don't want that.


brucegust.com/qr/index.php?id=12345 needs to be...

RewriteEngine On
RewriteRule /

How do I structure my RewriteRule?
Julian HansenCommented:
AddType x-mapp-php5 .php
Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ([0-9]+)$ qr/index.php?id=$1 [L,NC,QSA]

Open in new window

PHP - qr/index.php

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now