将文档根目录设置为public后,无法访问公共资源
我刚刚开始在一个新项目中使用Laravel,并且遇到了问题。将文档根目录设置为public后,无法访问公共资源
因此,我认为我已经为一个新项目设置了一切,并开始研究它。在我的本地机器(Windows,运行WAMP)上一切正常,我已经在个人VPS(Ubuntu,运行NGINX)上设置了它,它也工作正常。现在,我的雇主正在使用共享主机,访问可悲的是非常有限。我有ftp访问,他可以访问cPanel上的一些东西。我试着直接从本地项目中使用PhpStorm部署到服务器。看起来没问题,只有碰撞是指向文件列表,但在访问serverlink/public时似乎没问题。我已经要求我的雇主将文档根目录更改为/ public,因此我无法访问我的资源(css/images),这些资源是公开/公开的。生成的链接是它们应该是例如:serverlink/css/mycss.css,但该文件返回一个404,这很奇怪。
这里是我的htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule^index.php [L]
</IfModule>
在我的意见,我用刀片引用的资产,就像这样:
<link href="{{ asset('css/button.css') }}" rel="stylesheet" type="text/css" >
我能得到什么试图直接访问浏览器中的文件时,是
“对不起,找不到页面。” 1/1 NotFoundHttpException in RouteCollection.php line 145:“
任何人都可以帮我吗?坚持这一点,尤其是因为它在我的vps上运行良好!由于托管限制,我需要放弃Laravel 5吗?还是可以绕过它们?
干杯, 蒂亚戈C.
加入这一行的index.php
$app->bind('path.public', function() {
return __DIR__;
});
并改变公共目录主目录。
事实证明,在根目录下需要验证的.htaccess存在问题。不知何故,我想当根文件夹被设置为公开时,其他.htaccess阻止访问文件(因为没有提出auth)。我因为编辑出来,并改变了我的.htaccess(内公开)本:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /public
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</IfModule>
其中也取消了“的index.php /”或在我的路线similiar的需要。
干杯!
'asset('css/button.css')'呈现的是什么?什么'url()'返回? – user2094178
[.htaccess重定向除css和javascript之外的所有扩展名]的可能重复(http://*.com/questions/15202316/htaccess-redirect-all-extension-except-css-and-javascript) – Jigar