0

I am storing all of image at custom directory at laravel project root folder.


Custom directory means i have created new folder like "upload_files" at root directory.

whenever i am calling any files from this directory url be like "http://domainName.com/upload_files/folderName/fileName.jpg
But it's loading at web view.


Note : Image are loading from public directory.
Here is my .htaccess file code below
Note : I created new .htaccess file at root directory instead public folder .htaccess both file are exisiting at the project
<IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
      Options -MultiViews
    </IfModule>

     RewriteEngine On

     RewriteCond %{REQUEST_FILENAME} -d [OR]
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteRule ^ ^$1 [N]

   RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
   RewriteRule ^(.*)$ public/$1



   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ server.php

   </IfModule>

   # Deny index view Options -Indexes

   # Deny view a specific file <Files .env>    Order allow,deny    Deny from all </Files>
4

1 回答 1

1

在这些行之前

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1

尝试添加这个

RewriteCond $1 !^(upload_files)

这将允许访问 upload_files

<IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
      Options -MultiViews
    </IfModule>

     RewriteEngine On

     RewriteCond %{REQUEST_FILENAME} -d [OR]
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteRule ^ ^$1 [N]

     RewriteCond $1 !^(upload_files)

     RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
     RewriteRule ^(.*)$ public/$1



     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^ server.php

   </IfModule>

   # Deny index view Options -Indexes

   # Deny view a specific file <Files .env>    Order allow,deny    Deny from all </Files>

这应该可以解决问题

RewriteRule ^(.*)$ public/$1

表示您的所有请求都将发送到公共文件夹。所以这里我们排除了对upload_files

RewriteCond $1 !^(upload_files)
于 2020-06-30T15:15:47.933 回答