• Resolved codepoet

    (@codepoet)


    i have noticed that https://siteurl/random/path (where /random/path is any path that doesn’t actually exists as a file or directory) is happily accepted by wordpress, which proceeds to serve the site front page.

    i am using nginx and the ‘offending’ config there is:

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

    which is apparently the accepted configuration with wordpress. looks like it makes sense for a php web app.

    i may be misunderstanding something, but here are my questions at the moment:

    why is wordpress serving content for a meaningless uri? how do you make it stop? failing that, can nginx be made to do it without breaking wordpress?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Does your theme include a 404.php error file template?

    Thread Starter codepoet

    (@codepoet)

    thanks for your reply, esmi. no, it didn’t have a 404.php file, but i added one in the theme root. still seeing the same behaviour.

    I freely admit to know very little about nginx but have you tried removing that line from the config so that WordPress can handle the 404s?

    Thread Starter codepoet

    (@codepoet)

    esmi, you were partially correct.

    i discovered that try_files line is designed to work well with wordpress’s permalinks functionality. with permalinks off, index.php ignores the request path and just serves the front page. strange behaviour. only with permamlinks enabled will wordpress return a ‘not found’ page when you enter something invalid.

    i think without that line the default is equivalent to ‘try_files $uri;’, meaning that an actual object must exist at the requested path.

    so, i believe the answer is: omit try_files or use ‘try_files $uri;’ without permalinks, but with permalinks enabled the wordpress index.php handles things correctly.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘siturl/random/path serves front page’ is closed to new replies.