1

I'm using Nginx and a custom add_rewrite_rule that looks like this:

function add_pony() {
  //this should allow me to POST to domain.com/pony
  add_rewrite_rule('^pony$', 'index.php?pony=true', 'top');
}

add_action( 'init', 'add_pony');

function parse_pony( $params ) {
  if(isset($params->query_vars['pony'])){
    //kick off endpoint specific code
  }
  return $params;
}

add_action( 'parse_request', 'parse_pony' );

My nginx config for WP looks like this:

server {
    listen 80;

    root /var/www/domain.net;
    index index.php;

    server_name domain.net;

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

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
              root /usr/share/nginx/www;
        }

        location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        include fastcgi_params;
     }
}

When I POST or GET the new URL I get a 404. The rest of WordPress works just fine, but when I change the permalink settings to something other than post-name, WordPress stops working correctly.

I'm stumped.

  • did you flush rewrites after adding the rule? – Milo May 4 '15 at 19:56
  • Yes I did. I downloaded the rewrite rules inspector plugin and everything looked good there too. – Adam Simpson May 4 '15 at 20:27
0

Solved. Nginx and WordPress were acting correctly. There was an error condition further down my request processing code.

0

Update: I found my problem, if anyone else gets this problem then check if your server configuration is properly set to use .htaccess file. An easiest way to check that in your wp installation is to type in an url address that doesn't exist after your wordpress host, e.g.: http://your-domain.com/location-that-doesnt-exist

If your server is properly configured to use htaccess files then when you type the above like url you'll see styled 404 page with wordpress theme.

If it is NOT properly set then you will see server's default 404 page, it will not have wordpress theme.

Hope that helps someone.

  • 1
    Umm, nginx does not use .htaccess files. – Andres Mar 25 '16 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.