从 URL Laravel 5.3 中删除 public
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40099732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove public from URL Laravel 5.3
提问by KBK
采纳答案by iCoders
copy both htaccess and index.php file from public folder to root directory and then change root index.php code as below
将 htaccess 和 index.php 文件从公共文件夹复制到根目录,然后更改根 index.php 代码如下
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
回答by Alexey Mezenin
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
安装 Laravel 后,您应该将 Web 服务器的文档/Web 根目录配置为公共目录。此目录中的 index.php 充当所有进入您的应用程序的 HTTP 请求的前端控制器。
https://laravel.com/docs/5.3/installation#configuration
https://laravel.com/docs/5.3/installation#configuration
Do not edit .htaccess
or Laravel related files, just point web server to a public
directory instead of Laravel project directory:
不要编辑.htaccess
或 Laravel 相关文件,只需将 Web 服务器指向一个public
目录而不是 Laravel 项目目录:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
Then restart Apache.
然后重新启动Apache。
回答by KBK
Yes it is very simple no need to add extra htaccess,
是的,非常简单,无需添加额外的 htaccess,
- Create a new folder in your laravel project folder.
- Name it whatever you like. Example :- source
- 在 Laravel 项目文件夹中创建一个新文件夹。
- 随便给它起个名字。示例:- 来源
- Move all the files from root into 'source' folder except 'public' folder.
- 将所有文件从根目录移动到“源”文件夹中,“公共”文件夹除外。
4 . Move all the files from public folder to root.
4 . 将所有文件从公共文件夹移动到根目录。
5 . Change the autoload.php path
5 . 更改 autoload.php 路径
6 . Thats all. remove public folder if necessary.
6 . 就这样。如有必要,删除公用文件夹。
回答by Risul Islam
Add a .htaccess
file in root which contains -
.htaccess
在根目录中添加一个文件,其中包含 -
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
回答by Santosh Kumar
In the root directory create a .htaccess file and put the following in it
在根目录创建一个 .htaccess 文件并将以下内容放入其中
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
回答by ShuBham GuPta
Even above solution(s) work(s) for you,but I would recommend not to do this.
Here is the reason why.
-You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
-you have to configure apache for user not access .env, git files , config folder's file
public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition.
即使上述解决方案对您有用,但我建议不要这样做。这是原因。
- 您应该将 Apache 主机根目录指向 $LARAVEL_PATH/public 目录而不是 $LARAVEL_PATH。
- 您必须为无法访问 .env、git 文件的用户配置 apache,配置文件夹的文件
公共目录是为了使项目更安全。解决实际问题,不要试图破坏这个简单但很好的安全性添加。
回答by Akshay Deshmukh
Copy all files and folder from public folder to root folder and edit your .htaccess
file as
将所有文件和文件夹从公用文件夹复制到根文件夹并将.htaccess
文件编辑为
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
And dont forget to change the paths in index.php file. For details refere following links
并且不要忘记更改 index.php 文件中的路径。详情请参考以下链接
Installing Laravel in a subfolder
https://ellislab.com/forums/archive/viewthread/151342/#734511
https://ellislab.com/forums/archive/viewthread/151342/#734511