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?

  • 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
  • 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

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.


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).

  • 1
    Thanks for the security tips by the way (never too late to upvote ;) ) – Jeremy Dicaire May 16 '17 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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