I
I
IdFox2017-11-16 06:40:40
Yii
IdFox, 2017-11-16 06:40:40

How to register a route in YII2 for downloading a file through authorization?

Good
afternoon I just can’t figure out how to write rules in YII2 and htaccess to download files through authorization
The essence is this, it used to be WP
Download links were of the form (for example), they worked through authorization
https://xxxx.ru/data/uploads/filebase/ xxxx.pdf
Now everything has been transferred to YII2, you need to save all the paths and logic
In .htaccess I write
RewriteRule ^data/uploads/filebase/(.*)$ index.php
Yii2 gets control, but cannot recognize the route in any way, which is logical in principle
Editing the parameters of the urlManager doesn't really help either, the route is not recognized and that's it.
That is, for example, I prescribe But the rule does not work...
'data/uploads/<file_data>' => 'site/test',
How to write everything correctly, tell me, I can’t even figure it out
Thanks in advance for the tips

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IdFox, 2017-11-16
@IdFox

In general, we decided not to fence the garden
. Fortunately, nginx is.
Made in the config

location /data/uploads/filebase {
    rewrite ^(.*)$ /site/test/?file=$1 last;
    return 403;
}

location /download {
    internal;
    alias /var/www/www-root/data/www/SITENAME/www/data/uploads/filebase;
}

And issuance through
header('X-Accel-Redirect: /download/test.txt');

A
Arman, 2017-11-16
@Arik

Normally php is run when the web server doesn't find the file, this is how routing (CNC) usually works. When wp was standing, did he just give the link to the authorized ones or did he not directly give the file to the guests?
To close the file, you need to either distribute files through php, but the load will be decent, or rename them all the time. There is still an opportunity to decide through nginx, it seems that you can make it ask which script can give the file or not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question