重定向到公共文件夹流明(Laravel)文件夹、重定向、Laravel

2023-09-02 00:23:37 作者:夢與遠方△

我有一个很大的问题。我工作在本地主机与流明框架的应用程序。 我的工作环境是对WAMP(Windows)中。

I have a big problem. I work on an application in localhost with Lumen framework. My work environment is on Wamp (Windows).

流明需要的根是在公开文件夹。

Lumen requires the root to be in the public folder.

要做到这一点,我有这样的一个配置文件:

To do that, I have a configuration file like this :

NameVirtualHost name.local
<VirtualHost name.local>    
  DocumentRoot C:/wamp/www/name/public
  ServerName name.local  
</VirtualHost>

所以,如果我把地址 name.local / 在我的浏览器,我可以达到索引页。

So, if I put the address name.local/ in my browser, I can reach to the index page.

现在,我需要把我所有的工作在一台FTP。在那里,我有一个异常错误,这是正常的,因为我的根不在公开文件夹。

Now, I need to put all my work in a FTP. And there, I have an exception error, which is normal because my root isn't the public folder.

更新:我已经找到答案,请看下面的这

推荐答案

好了,搜索了几天之后,我已经找到了解决方案。

Ok, after days of search, I have found the solution.

添加的.htaccess 文件中的应用程序的根,并在此文件中添加这样的:

Add a .htaccess file in the root of the application and add this in this file :

RewriteEngine On

RewriteCond %{THE_REQUEST} /public/([^s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

假设你没有触及腔的原有的建筑和公共数据仍然在同一个地方:在公共/ 文件夹

编辑:

通过腔和Laravel的最后一个版本,你只可以在的.htaccess 文件写的:

With the last version of Lumen and Laravel, you just could write it in the .htaccess file :

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

或者按照本教程