Redirect to public folder on Lumen (Laravel)

17.7k views Asked by At

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>

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

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.

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

1

There are 1 answers

2
w3sic3 On BEST ANSWER

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

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]

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

EDIT :

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

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

Or follow the second method of this tutorial