Rewrite part of URL if it contains a specific string

Hello,

my cakphp app is located in folder in root web directory, i.e. /www/myapp

Files that are uploaded through web form are saved in /www/myapp/webrooot/uploads folder.

Each file is related to one record in my table and link to open the file is always added to respective view template.

Nevertheless, the link works correctly only when my app is located in root www folder, i.e. this link works:

http://myapp/uploads/file_id_12345.pdf

When I put my app into subfolder, the link opens as follows:

http://localhost/myappuploads/file_id_12345.pdf

Is there any way how to fix this using routes? E.g. to automaticaly replace /myappuploads/ with /myapp/uploads/?

Thank you for any hint.

I don’t think it is a good idea uploading files to the webroot folder.

Can you share the code where you are saving the file and accessing to it?

I’m not sure what you are trying to achieve but this might help you: Request & Response Objects - 4.x

Thank you for your reply. Finally it was enough to add slash before each link to the uploaded file, i.e. to change it from:

echo $this->Html->link(__(“Show scan”), h($notification->scan_of_the_notification),[‘target’ => ‘_blank’]);

to:

echo $this->Html->link(__(“Show scan”), h(‘/’.$notification->scan_of_the_notification),[‘target’ => ‘_blank’]);

where:

$notification->scan_of_the_notification

is equal to:

uploads/file_id_12345.pdf

Nevertheless, where can I lear the proper way of uploading and dislaying files, i.e. not placing and storing them in uploads folder?

Thank you.