Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a way to convert this type of URL:


Into http://www.example.com/dl/files/my_file.zip using a PHP page to request the URL from the DB with F5EGD6. I tried ith this htaccess file :

RewriteEngine on
RewriteRule (*)$ /dl.php [QSA]

But it doesn't work. I get Error 500 :(

I don't know how to handle that...

Anyone know?

share|improve this question
You should check out any of the many mod_rewrite tutorials out there. They explain how to do this quite well. – John Conde Oct 23 '10 at 3:10
Thank you very much John :) – Jeremy Dicaire Oct 23 '10 at 3:21
Is h11p a typo? Twice? – Thomas Oct 23 '10 at 3:53
LOL I'm not alowed to put links since I don't have many reputation points :) – Jeremy Dicaire Oct 23 '10 at 16:28
up vote 1 down vote accepted

If I were going to transform




I would do something like

RewriteRule ^dl/files/(.*)$ dl.php?what=$1

That matches http://www.example.com/dl/files/anythinghereincludingslash/ and would transform it into http://www.example.com/dl.php?what=anythinghereincludingslash/.

I think that's probably what you're looking for.

N.B. mod_rewrite would need to be enabled.

share|improve this answer

I'd do it this way:

RewriteEngine on 
# Check if the requested url stats with /dl/
RewriteCond %{REQUEST_URI} ^/dl/
#if so, redirect everything to dl.php, placing everything in $_GET['url']:
RewriteRule ^dl/files/(.*) /dl.php?url=$1 [L]

Requesting http://www.example.com/dl/files/my_file.zip will result in calling dl.php, where $_GET['url'] == 'my_file.zip'. The user will not see this in the urlbar, they'll just keep seeing their original url.

Safety tip: It's obvious you have to use a file_exists(), but do not forget to check if ../ is in the url. If I where to call example.com/dl/files/../../index.php, I'd get your index.php, or any other file I want (if I knew your file structure).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.