How to route to a static folder in Laravel

前端 未结 3 1800
夕颜
夕颜 2020-12-25 12:24

I have a folder I\'ve placed in the /public folder in my Laravel site. The path is:

/public/test

the \"test\" folder has a file called inde

3条回答
  •  孤独总比滥情好
    2020-12-25 12:52

    For a static file, I think you're wasting resources serving it through Laravel.

    There have been some bugs in the past creating infinite redirects when trying to access files/folders within public, but I think the latest .htaccess that comes with Laravel has these resolved (on Apache, at least). It looks like this

    
        
            Options -MultiViews
        
    
        RewriteEngine On
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    
    

    It says 'If the request is not for an existing folder, strip the trailing slash if there is one. If the request is not for an existing folder or for an existing file, load Laravel's index.php'

    I then added a .htaccess file within the subdirectory to ensure that the DirectoryIndex is set so that index.html will be loaded by default on a request for a directory.

提交回复
热议问题