4

I want to only allow the priviledged user to download some special file.

So I config apache2 with below, which make /data/model/userModel cannot directly accessable.

Alias /user_model "/data/model/userModel"
<Directory /data/model/userModel>
            Order allow,deny
            Deny from all
</Directory>

While the /data/model/userModel may have subfolders, like

  • /data/model/userModel/pic/tiny/aaa.png
  • /data/model/userModel/txt/aaa.txt
  • /data/model/userModel/model/0/13/aaa.zip

This path is just for file download, in the controller method I just check if the user have to right to download file. So I try to use only one route for these pathes. For example,

Route::get('user_model/*', 'ModelController@user_model');

While it not works. The * in the route only can match one segment of the url.

How can I make one route match url with scalable segments length. I don't know my design of the route here is proper.

LF00
  • 27,015
  • 29
  • 156
  • 295
  • Is this what you're looking for: https://stackoverflow.com/questions/34831175/how-do-i-make-a-catch-all-route-in-laravel-5-2 – Nathan Heffley Nov 07 '17 at 03:52
  • 1
    Possible duplicate of [How do I make a Catch-All Route in Laravel 5.2](https://stackoverflow.com/questions/34831175/how-do-i-make-a-catch-all-route-in-laravel-5-2) – Nathan Heffley Nov 07 '17 at 03:52
  • @NathanHeffley thank you. it works for me. – LF00 Nov 07 '17 at 04:14

1 Answers1

4

Enlighted by How do I make a Catch-All Route in Laravel 5.2 in Nathan Heffley's comment , I solve it.

Use Route::get('user_model/{path}', 'ModelController@user_model')->where('path', '.*'); instead of Route::get('user_model/*', 'ModelController@user_model');.

Note:

  • * in Route::get('user_model/*', 'ModelController@user_model'); only can match one segment.

  • * in Route::get('user_model/{path}', 'ModelController@user_model')->where('path', '.*'); can match multi segments.

LF00
  • 27,015
  • 29
  • 156
  • 295