从Laravel子域中托管的url中删除public [英] Remove public from url hosted in sub domain in Laravel
本文介绍了从Laravel子域中托管的url中删除public的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经将我的Laravel网站托管在子域中,其网址是这样的:
I have hosted my Laravel site in sub domain, its url is something like this:
现在我想从网址中删除公众,我的.htaccess文件就像:
Now i want to remove the public from url, my .htaccess file is like:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}/beta [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
推荐答案
将所有文件从/public
移至根文件夹/
(主要是laravel文件夹)
Move your all files from /public
to your root folder /
(which mainly your laravel folder).
现在打开 index.php
文件并编辑2行,如下所示:
Now open index.php
file and edit 2 lines, as below :
require __DIR__.'/../vendor/autoload.php';
// changed to
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
// changed to
$app = require_once __DIR__.'/bootstrap/app.php';
现在将此行添加到您的 .htaccess
中,以防止从URL访问 .env
:
Now add this lines to your .htaccess
to prevent access .env
from URL :
<Files .env>
order allow,deny
Deny from all
</Files>
通过这种方法,您也可以在任何类型的共享托管中托管laravel应用.
By this method you can host your laravel app in any kind of shared hosting too.
希望这对您有帮助
这篇关于从Laravel子域中托管的url中删除public的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文