: 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
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?
More posts by @Correia994
2 Comments
Sorted by latest first Latest Oldest Best
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).
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.