Nginx configuration for Laravel


nginx

Laravel offer you file .htaccess with content:

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

It use with Apache, how to convert it to use with Nginx:

		# removes trailing slashes (prevents SEO duplicate content issues)
		if (!-d $request_filename)
		{
			rewrite ^/(.+)/$ /$1 permanent;
		}
 
		# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
		if (!-e $request_filename)
		{
			rewrite ^/(.*)$ /index.php?/$1 last;
			break;
		}

		location / {
			try_files $uri $uri/ /index.php?$query_string;
		}

Leave a Reply