Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

.htaccess - Redirect to public folder on Lumen (Laravel)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...