Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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;
}
@momokang

This comment has been minimized.

Copy link

@momokang momokang commented Oct 3, 2018

Thanks for the solution, but you might have url like domain.com/index.php/slug, to solve this:

# Remove index.php$
if ($request_uri ~* "^(.*/)index\.php/*(.*)") {
    return 301 $1$2;
}
@gyan111

This comment has been minimized.

Copy link

@gyan111 gyan111 commented Dec 13, 2018

Where shall we put it?

I am getting "domain.com/index.php/slug"

I am on lighttpd server.

@cafeasia3

This comment has been minimized.

Copy link

@cafeasia3 cafeasia3 commented Nov 15, 2019

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

I cant login phpmyadmin with this code, stuck at login screen. domain.com/phpmyadmin.

@ANILKEN

This comment has been minimized.

Copy link

@ANILKEN ANILKEN commented Jan 22, 2020

Thanks, it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment