4
server {
location / {
            try_files $uri $uri/ @extensionless-php;
    }
location /shop {
           try_files $uri $uri/ /shop/index.php?q=$uri&$args /shop/index.php?q=$uri&$args;
    }
location ~ \.php$ {
             if ($request_uri ~ (.*)\.php$)
    {
             return 301 $1;
            }
             try_files $uri =404;
             include /etc/nginx/fastcgi.conf;
             fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        }
location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
}

The above code is used in nginx server file. I have wordpress installed in a subdirectory. When I try to login into my dashboad using username and password through wp-login.php page it redirects to 404 not found. The other pages of the wordpress blog works fine. I cannot access my dashboard only. Please help me to solve the issue. Thanks in advance.

1 Answer 1

2

You may want to add a separate (nested) location ~ \.php$ block for WordPress to isolate it from the extension-less PHP rules used for the rest of your site.

For example:

location / { ... }

location ^~ /shop {
    try_files $uri $uri/ /shop/index.php?q=$uri&$args;
    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

location ~ \.php$ { ... }

location @extensionless-php { ... }

The ^~ modifier gives the prefix location higher precedence than the regular expression locations at the same level. See this document for details.

1
  • 3
    @Pal If this answered your question then please consider marking it as "accepted" (checkmark on the left below the voting arrows) to give credit and help other users. You can also "upvote" answers you find useful. Thanks, much appreciated. :)
    – MrWhite
    Commented Apr 28, 2019 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.