Support » Fixing WordPress » pretty permalink is invalid show 404 page.

  • Resolved bearshang

    (@bearshang)


    Too bad, pretty permalink is invalid, and now only the default url is valid; when i select /% postname% /, except for the home page and the custom post type archive page, all other pages jump to page 404 I do not understand why this is…

    And when I opened the same theme in another domain name, this situation will not happen, obviously, is not the subject or plug-in reasons;

    The environment of the site is:
    Nginx 1.12.0,Centos 6.8 and php7.1.4.

Viewing 6 replies - 1 through 6 (of 6 total)
  • @bearshang,

    Nginx can be tricky when configuring for WordPress. WordPress expects apache and so it loads permalink settings into a hidden file inside the root HTML directory called .htaccess. This file contains settings for Apache to use, including how to redirect based on your sites permalinks.

    With Nginx, however, you’ll need to do this inside your Nginx configuration. I’m unsure where the config lives on Centos, but look somewhere inside of /etc/nginx/. Be sure to edit your site settings, not global Nginx config.

    You’ll need to pass along the location and redirection settings to the file, similar to this:

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

    Check the sources below for a bit more detailed information. I would also recommend following the WordPress.org Nginx link for more configuration options.

    Sources:

    Hope this helps and let me know if you have any follow up questions!

    Tom

    To improve Tom’s answer (that covers everything to make permalinks work)…

    The following is more precise, as it adds the question mark after index.php file, only if any query strings (or $args) are present.

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

    .

    +1 Thanks @pothi!

    @tm3909
    How to say it…

    I follow the methods in the data are tested, the problem still exists…

    This is my nginx configure:

    
    server
        {
            listen 80;
            server_name dev.trueniu.com *.dev.trueniu.com;
            index  index.php index.html index.htm;
            root  /home/wwwroot/trueniu-php/trueniu;
    
            include enable-php.conf;
            include wordpress.conf;
        }
    

    wordpress.conf:

    
    access_log /home/wwwlogs/nginx_access.log;
    
    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
    }
    

    And I tried your method @pothi ,Unfortunately,he does not seem to have any effect;

    So I boldly guess the problem should not be on the nginx configuration,
    Because I use the multi-site subdomain mode, in the same wordpress program under the other sub-domain site performance is good, and did not appear this problem.

    There must be something else that causes this problem to happen.-_-

    @tm3909
    @pothi

    Lucky, I found the reason, not the result of nginx configuration, but a multi-language plug-in cause, The plugin name is ‘Polylang’…

    I use this plugin and add a language at the same time that could destroy the permalink structure, causing permalink to fail…

    Thank you very much for your reply!

    @tm3909
    @pothi

    I found a solution to the problem:

    
    add_action( 'init', 'flush_rewrite', 99 );
    function flush_rewrite()
    {
        flush_rewrite_rules();
    }
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘pretty permalink is invalid show 404 page.’ is closed to new replies.