Mobile app version of vmapp.org
Login or Join
Correia994

: File need to go through a php page using .htaccess I'm looking for a way to convert this type of URL: http://www.example.com/dl/F5EGD6 Into http://www.example.com/dl/files/my_file.zip using a PHP

@Correia994

Posted in: #Htaccess #HttpCode500 #Php #UrlRewriting

I'm looking for a way to convert this type of URL:
www.example.com/dl/F5EGD6

Into 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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Correia994

2 Comments

Sorted by latest first Latest Oldest Best

 

@Chiappetta492

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= [L]


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

10% popularity Vote Up Vote Down


 

@Correia994

If I were going to transform
www.example.com/dl/files/zip.zip

into
www.example.com/dl.php?what=zip.zip

I would do something like

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


That matches www.example.com/dl/files/anythinghereincludingslash/ and would transform it into 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme