繁体   English   中英

在共享主机上的目录文件夹中运行laravel项目

[英]Run laravel project in a directory folder on shared hosting

我的问题是:如何在共享虚拟主机上的目录(不是root)中运行laravel应用程序?

对于我的一些客户,我在其选定的共享虚拟主机的根文件夹中运行Laravel应用程序,并从URL中删除/ public部分。 为了完成这项工作,我将index.php移动到根文件夹,并将index.php中的信息更改为:

require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

现在我知道这可能会导致安全问题,但我已经找到了共享webhosters的解决方案。

我用来做这个改变的.htaccess是:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.eot|\.woff|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1/$2 [L,NC]

但在这种情况下,我希望laravel项目在名为test的目录中运行。

文件夹结构:

root (public_html)
  |-- test (directory with laravel project)

现在我不确定我是否可以简单地更改.htaccess,因为我不熟悉.htaccess文件。 为了使这项工作,我必须做出哪些改变?

请注意我的网址:

// this link will be changed to:
    www.[text-placeholder].com/test/public/css/style.css 

// Output above result now:
    www.[text-placeholder].com/public/css/style.css

// But should be:
    www.[text-placeholder].com/test/public/css/style.css 

这很简单,只需将项目放在public_html文件夹上1级,并将公用文件夹本身重命名为public_html。

在此输入图像描述

PS这可能是比使用.htaccess更好的方法,因为现在你确实知道公共html之外的文件不在你的webroot中(黑客无法访问),而且你可以使用htaccess出错,文件是裸露。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM