R
R
Ruslan Banochkin2020-06-09 23:17:54
Nginx
Ruslan Banochkin, 2020-06-09 23:17:54

How to deal with 404 errors on urls without an extension at the end?

Recently completely switched from apache to nginx. Everything would be fine, but there was a problem with self-written scripts in php.

The domain is linked, the site itself consists of one index.php, a couple of pictures and css. Made another 404.php page for the corresponding error. I registered the following in the nginx config: I

error_page 404 /404.php;

open site.ru/blablabla.php - everything is processed as it should, in the browser exactly what is written in the 404.php file.

But it’s worth opening site.ru/blablabla - what opens in my index.php.

Googled all day looking for a solution - nothing. I read the official manual - also nothing. How to solve this problem? I'm sure this is a simple question and I don't see some banal thing, but I'm already tired of looking for a solution to the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wexter, 2020-06-09
@Wexter

But it’s worth opening site.ru/blablabla - what opens in my index.php.

lay out the config

D
dodo512, 2020-06-10
@dodo512

server {

    ...
    
    error_page 404 /404.php;
    
    index index.php;
    
    location / {
    
    }
    
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass ... ;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question