重定向到 Lumen (Laravel) 上的公共文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30740023/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:44:52  来源:igfitidea点击:

Redirect to public folder on Lumen (Laravel)

.htaccesslaravellumen

提问by w3spi

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

我有一个大问题。我使用 Lumen 框架在本地主机上开发一个应用程序。我的工作环境在 Wamp (Windows) 上。

Lumen requires the root to be in the publicfolder.

Lumen 要求根目录位于public文件夹中。

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>

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

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

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 publicfolder.

现在,我需要将我所有的工作放在一个 FTP 中。在那里,我有一个异常错误,这是正常的,因为我的根目录不是public文件夹。

UPDATE : I have find the answer, please see it below.

更新:我找到了答案,请在下面查看。

回答by w3spi

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

好的,经过几天的搜索,我找到了解决方案。

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

.htaccess在应用程序的根目录中添加一个文件并将其添加到此文件中:

RewriteEngine On

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

Assuming you haven't touched the original architecture of Lumen, and that public data is still in the same place : the public/folder

假设你没有接触过 Lumen 的原始架构,并且公共数据还在同一个地方:public/文件夹

EDIT :

编辑 :

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

使用 Lumen 和 Laravel 的最新版本,您只需将其写入.htaccess文件:

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

Or follow the second method of this tutorial

或者按照本教程的第二种方法