Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix How to return 404 instead of redirecting to homepage

Discussion in 'Misc WordPress Requests' started by johns2017, Nov 20, 2017.

  1. johns2017

    Guest

    How to return 404 instead of redirecting to homepage, by johns2017

    Greetings Gods of WordPress!

    Problem:
    I’m running a fresh WordPress 4.9 install with no plugins and the Twenty Seventeen theme. Permalinks are custom structure: /blog/%postname%/. Homepage is a static page.

    When I browse to non-existent page domain.com/blog/invalidurl WordPress returns the themes 404 page. Perfect.

    However when I browse to any non-existent page on the top level, e.g. domain.com/invalidurl or domain.com/invalidurl/missingfile.html then WordPress 301 redirects to domain.com

    How do I get WordPress to return a 404 for any non-existent file on the top-level site instead of 301 redirecting to the homepage at domain.com?

    Environment:
    Ubuntu 16.04.2 with PHP 7.0. The web frontend is NGINX, configuration:


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

    # deliver a static 404
    error_page 404 /404.html;
    location /404.html {
    internal;
    }

    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php?$args;
    }


    Appreciate any help you can offer.

    How to return 404 instead of redirecting to homepage
     
    #1

Share This Page

Web Hosting