简体   繁体   中英

Laravel public folder subfolder

I have laravel folder like this

  • app
  • vendor
  • bootstrap
  • public
    • folder
    • img

when I access from url http://example.com/img/img.png it works But when i access like http://example.com/img/ I get Forbidden 403, What I need is to redirect or to show that page not found My .htaccess looks like this.

Options -MultiViews Options -Indexes RewriteEngine On

 RewriteCond %{HTTP_HOST} ^234\\.123\\.1\\.11 RewriteRule (.*) https://www.example.com/$1 [L,R=301] RewriteCond %{HTTPS} off # First rewrite to HTTPS: RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. RewriteCond %{HTTP_HOST} !^www\\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] </IfModule> 

I'd say setup a simple route like in the routes.php like so:

Route::get("/img", function(){
    return Redirect::to('/');
});

this should do the trick. editing your .htaccess isn't really nessecary unless you really have no other way of doing this kind of things

Changed my .htaccess to

Options -MultiViews Options -Indexes RewriteEngine On

 RewriteCond %{HTTP_HOST} ^28\\.42\\.53\\.24 RewriteRule (.*) https://www.example.com/$1 [L,R=301] RewriteCond %{HTTPS} off # First rewrite to HTTPS: # Don't put www. here. If it is already there it will be included, if not # the subsequent rule will catch it. RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. RewriteCond %{HTTP_HOST} !^www\\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> 

Source:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM