重定向到 Lumen (Laravel) 上的公共文件夹 [英] Redirect to public folder on Lumen (Laravel)

查看:57
本文介绍了重定向到 Lumen (Laravel) 上的公共文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题.我使用 Lumen 框架在本地主机上开发一个应用程序.我的工作环境是 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 要求根位于 public 文件夹中.

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 中.在那里,我有一个异常错误,这是正常的,因为我的根目录不是 public 文件夹.

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]

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

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

使用 Lumen 和 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]

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

这篇关于重定向到 Lumen (Laravel) 上的公共文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆