Block opening images by typing the full path into the address bar. Laravel 9

  Kiến thức lập trình

I know this is a topic already covered but I’ll explain my problem. Initially the project was developed with the resources exposed in plain text in the public folder. Each image that is uploaded is located in an images subfolder and it is located in images which in turn is located in Laravel’s public folder so the full path would be public_path/images/images/filename.jpg
now they asked me not to make the resources clear anymore so if I write the complete address of the image in the URL I can view it. I don’t want to change the destination in storage because it would be too much work. Is there a way to not display the images? I have already tried with a middleware and .htaccess but nothing to do. I hope you can help me.

.htaccess code

Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    RewriteRule ^public/images/images/(.*)$ - [F,L]
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

LEAVE A COMMENT