问题描述
我是Laravel框架的新手,所以这个问题可能有点愚蠢,但这是问题所在:
I'm new to Laravel framework so this question might be a little stupid but here's the problem:
我在本地计算机上有一个小项目,现在我需要将项目部署到实时环境(共享主机)中.
I have a small project on my local machine and now I need to deploy my project to a live environment ( shared hosting ).
问题是,我的项目需要存储在主域的子目录(子文件夹)中(例如,我的域将是 main.com ,并且该项目将是在 main.com/my-project ).我在主域的public_html内创建了一个子文件夹,然后将项目上传到该子目录.最初,当我进入url main.com/my-project 时,我看到一个目录树(例如localhost),然后需要单击公用文件夹"以转到我的应用程序.因此,我在互联网上寻找解决方案,并尝试了.htaccess方式,这是我的.htaccess文件:
The problem is, my project needs to be stored in a sub-directory ( sub-folder ) of the main domain ( eg. my domain will be main.com, and the project will be at main.com/my-project ).I've created a sub folder inside the public_html of the main domain, then I uploaded my project to that sub-directory. At first, when I went to the url main.com/my-project, I see a directory tree ( like localhost ), then I needed to click to public folder to go to my app. So I looked for the solutions on the internet and I tried the .htaccess way, here's my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/project/public/
RewriteRule ^(.*)$ /project/public/$1 [L,QSA]
</IfModule>
但是当我重新加载URL main.com/my-project 时,我一直收到未找到的消息URL请求.
But when I reload the url main.com/my-project, I kept receiving the message URL request not found.
我已经在这个问题上苦苦挣扎了一段时间,但仍然没有弄清楚.知道如何解决这个问题吗?请帮帮我,谢谢.
I've been struggling with this issue for a while and still haven't figured it out. Any idea how I can solve this problem? Please help me out, thanks.
推荐答案
谢谢大家的帮助,实际上我已经以某种方式弄清楚了.对于那些可能遇到像我一样遇到同样问题的人,这是我的解决方案:
Thank you guys for helping, well actually I figured it out somehow. Here's my solutions for anybody who might run into the same problem like I did:
在/public_html内,我创建了一个文件夹并将其命名为my-project.在我的项目文件夹中,我放置了所有文件&资源文件夹(css,js)和.htaccess文件在这里.
Inside /public_html, I created a folder and named it my-project. Inside my-project folder, I placed all files & assets folders ( css, js ) and .htaccess file here.
然后,我回到父级(与/public_html相同),创建了一个文件夹并将其命名为app-core.我放置了所有其他Laravel的文件夹&文件在这里.
Then I went back to the parent level ( same level as /public_html ), I created a folder and name it app-core. I placed all the other Laravel's folders & files here.
结构将是这样的:
public_html
=app-core
--- All others files & folders except **public**
=my-project
--- index.php
--- css
--- js
--- .htaccess
最后,我回到编辑index.php的位置:
Finally, I went back to edit the index.php like this :
require __DIR__ . '/../app-core/vendor/autoload.php';
$app = require_once __DIR__ . '/../app-core/bootstrap/app.php';
并保存它,一切准备就绪!
And saved it, then everything was ready to go!
这篇关于如何将Laravel应用程序部署到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!