Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shashinvision/365d5daf98dd4c3ffa105c174dee59fb to your computer and use it in GitHub Desktop.
Save shashinvision/365d5daf98dd4c3ffa105c174dee59fb to your computer and use it in GitHub Desktop.
[nginx] laravel remove index.php from url
# Remove index.php$
if ($request_uri ~* "^(.*/)index\.php$") {
    return 301 $1;
}

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

    # Remove from everywhere index.php
    if ($request_uri ~* "^(.*/)index\.php(/?)(.*)") {
        return 301 $1$3;
    }
}

# Remove trailing slash.
if (!-d $request_filename) {
    rewrite ^/(.+)/$ /$1 permanent;
}

# Clean Double Slashes
if ($request_uri ~* "\/\/") {
    rewrite ^/(.*) /$1 permanent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment