Simple Lumen route request not working

I installed Lumen on my web server, but I have problems with routes

// http://12.345.678.910/ $app->get('/', function() use ($app) { return "This works"; }); 

But in this second case, he cannot find the directory

 // http://12.345.678.910/api $app->get('/api', function() use ($app) { return "This dont work"; }); 

In the second case, I get a standard 404 error.

 The requested URL /api was not found on this server. 

I am using Apache, Ubuntu, PHP 5.5 and Lumen

+7
laravel lumen
source share
2 answers

URL rewriting does not seem to work. If you add index.php to the url right before /api , will this work?

For example, yourdomain.com/api will become yourdomain.com/index.php/api , and if the second URL works, then rewriting does not work.

If your rewriting does not work, but you have a .htaccess file in your public directory, you probably need to allow overrides in your Apache configuration. Here is an example virtual host configuration for Lumen on Ubuntu.

I marked the lines that need to be changed. Change the first and third to point to the public directory in your website directory. Then change the second line to the domain name that you use on your website.

 <VirtualHost *:80> DocumentRoot "/var/www/lumen/public" # Change this line ServerName yourdomain.com # Change this line <Directory "/var/www/lumen/public"> # Change this line AllowOverride All # This line enables .htaccess files Order allow,deny Allow from all </Directory> </VirtualHost> 

You will need to restart Apache for these settings to take effect.

The best way

Including the .htaccess file should work, but using .htaccess slows down your site. The best solution is to put the contents of the .htaccess file in your virtual host and then disable the .htaccess files.

An example virtual host configuration for this is as follows:

 <VirtualHost *:80> DocumentRoot "/var/www/lumen/public" # Change this line ServerName yourdomain.com # Change this line <Directory "/var/www/lumen/public"> # Change this line # Ignore the .htaccess file in this directory AllowOverride None # Make pretty URLs <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> </Directory> </VirtualHost> 

Once again, you will need to restart Apache for these settings to take effect.

+7
source share

In the root of your application, create a .htaccess file if it is not already. Then paste the following code:

 Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] 

I assume you are using apache server and have included mod_rewrite .

Read the basic configuration section in the Lumen documentation .

If you don't know how to enable mod_rewrite , this stackoverflow may help you.

0
source share

All Articles