Php 如何在Laravel 5中设置基本路径
我将Laravel的公用文件夹移动到根文件夹,并将Laravel移动到它自己的文件夹。所以我可以在共享主机上使用Laravel。看起来是这样的:Php 如何在Laravel 5中设置基本路径,php,laravel,Php,Laravel,我将Laravel的公用文件夹移动到根文件夹,并将Laravel移动到它自己的文件夹。所以我可以在共享主机上使用Laravel。看起来是这样的: 2015/08/04 18:13 <DIR> . 2015/08/04 18:13 <DIR> .. 2015/08/01 17:50 896 .htaccess 2015/07/29 17:39 0 favico
2015/08/04 18:13 <DIR> .
2015/08/04 18:13 <DIR> ..
2015/08/01 17:50 896 .htaccess
2015/07/29 17:39 0 favicon.ico
2015/07/29 17:39 1,844 index.php
2015/08/04 17:19 <DIR> laravel
2015/08/04 17:20 <DIR> public
2015/08/01 17:46 1,165 README.md
2015/08/01 16:18 34 robots.txt
2015/08/04 17:20 <DIR> static
但是没有任何更改。不要移动公用文件夹,而是尝试在根目录中添加一个包含以下内容的.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
重新启动发动机
重写规则^$public/[L]
重写规则(.*)public/$1[L]
这会将所有请求重定向到/public您可以将其添加到/public文件夹中的index.php文件中,从而正确绑定公用文件夹
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
您可能希望在此之后清除缓存,因为之前可能已经缓存了路径。如果您在bootstrap/cache/config.php
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});