Laravel 5 使用 .htaccess 保护资产
Laravel 5 Protecting Assets With .htaccess
我的 public 目录中有一个不受 .htaccess 文件保护的资产文件夹。目前,我只是在资产文件夹中使用静态 index.html 页面,但我想要一种正确的重定向方式。我对 .htaccess 了解不多,因此非常感谢任何帮助。
我当前在 public 目录中的 .htaccess:
<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 ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如果您不想显示目录的内容,只需删除此行:
RewriteCond %{REQUEST_FILENAME} !-d
在这种情况下,文件的最后三行用来表示,"if the incoming request does not match an existing directory or file, then rewrite the request to index.php
for processing."
所以当你删除上面提到的行时,它会将任何对目录的请求传递给 index.php
。但是,由于剩余条件,此类目录中的文件仍将提供。
我的 public 目录中有一个不受 .htaccess 文件保护的资产文件夹。目前,我只是在资产文件夹中使用静态 index.html 页面,但我想要一种正确的重定向方式。我对 .htaccess 了解不多,因此非常感谢任何帮助。
我当前在 public 目录中的 .htaccess:
<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 ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如果您不想显示目录的内容,只需删除此行:
RewriteCond %{REQUEST_FILENAME} !-d
在这种情况下,文件的最后三行用来表示,"if the incoming request does not match an existing directory or file, then rewrite the request to index.php
for processing."
所以当你删除上面提到的行时,它会将任何对目录的请求传递给 index.php
。但是,由于剩余条件,此类目录中的文件仍将提供。