D
D
Dmitry Markov2019-07-10 14:29:34
Nginx
Dmitry Markov, 2019-07-10 14:29:34

How to set up a 404 error for everyone easily?

I decided to make a 404 error on the landing page.
site.com/index.php and site.com/index.html configured to redirect to site.com
site.com/ with 1 or more slashes to site.com
How to make sure that for all other requests we get to 404.php ?

server {        
        listen *:80;
        listen [::]:80;
        server_name site.com;
  
    access_log /var/www/vhosts/site.com/log/access.log combined;
    error_log /var/www/vhosts/site.com/log/error.log;

    rewrite_log on;
    rewrite ^/config.php/(.*)$ /config.php$1 last;

        root /var/www/vhosts/site.com/httpdocs;

        index index.php;
        include /etc/nginx/sites.conf.d/global.conf;

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

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php-fpm--site.com.sock;
        }

        if ($request_uri ~ "^(.*)index\.(?:php|html)") {
                return 301 $1;
        }

    if ($request_uri ~ ^[^?]*//) {
      rewrite ^ $uri permanent;
    }

    error_page 404 /404.php;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question