【发布时间】:2015-04-15 14:42:47
【问题描述】:
在 Laravel 5 中,我在用于 URL 重写的 .htaccess 和我的 CSS 文件之间存在问题。首先,这是我的项目树:
我的公用文件夹中有一个 .htaccess,如图所示。这是我的 .htaccess 的内容:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -Indexes
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^ index.php [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
这是我用来删除 URL 中的“index.php”的代码。例如,http://localhost/mySite/public/index.php/about 变为 http://localhost/mySite/public/about。
现在,我有一个母版页(在/resources/views/ 中),在这个母版页中我想引用位于/public/css/style.css 的css 文件。我在我的母版页中添加了这段代码:
<link rel='stylesheet' href="{{ URL::asset('css/style.css') }}" >
这不适用于当前的 htaccess,但如果我在我的 htaccess 中注释 RewriteRule ^ index.php [L] 行并访问 URL(使用“index.php”),则样式表被很好地引用。我想我必须在 htaccess 中添加另一行,但我不知道我必须添加什么。
我希望你能帮助我,并毫不犹豫地询问更多细节。谢谢。
【问题讨论】:
-
您对
.htaccess规则的重新排序破坏了它们。在改变之前了解它们。两行RewriteCond会改变以下RewriteRule的行为 - 没有后续行,它们将无效。
标签: php .htaccess mod-rewrite laravel laravel-5