How to route to a static folder in Laravel

久未见 提交于 2019-11-30 04:40:22

used to face this problem before, as a dirty little trick, you may rename the test folder to something else then update

return File::get(public_path() . '/to new folder name/index.html');

the key is no conflict between your route url with your folder in public

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

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

    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]
</IfModule>

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.

Use:

return Redirect::to('/test/index');

Either at the function at your routes file or inside a controller.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!