A
A
Andrey Skripnik2020-09-17 12:41:02
Nginx
Andrey Skripnik, 2020-09-17 12:41:02

How to redirect a request to another route in Laravel+Nginx?

There are files in the storage/app/public folder, access to which should be checked, if the file exists by reference, then nginx immediately gives it away, I tried to write a separate Route::get('storage/{file}') route, but it is naturally ignored .
Question: how can I redirect from storage / file_name to any route in Laravel for further processing of the request?

I tried in nginx config to do

location /storage/ {
            rewrite ^/storage/(.*) /index.php?путь break;
  	}

but of course nothing happened.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Skripnik, 2020-09-17
@andreskrip

Solved the problem by adding to the location config

location /storage/ {
    rewrite .* /index.php;
}

Now file request can be processed via
Route::get('storage/{file}', function ($file) {
    //
});

A
Anton Anton, 2020-09-17
@Fragster

Don't use public folder :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question