Forums

[resolved] siturl/random/path serves front page (5 posts)

  1. codepoet
    Member
    Posted 8 months ago #

    i have noticed that http://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?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    Does your theme include a 404.php error file template?

  3. codepoet
    Member
    Posted 8 months ago #

    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.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    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?

  5. codepoet
    Member
    Posted 7 months ago #

    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.

Reply

You must log in to post.

About this Topic