2

My Server configuration is:

  • Nginx
  • php-fpm5

I set up WordPress and it's working fine with custom permalink 'Day and name'. Now I want to set the rewrite rule in the nginx file and it's not working with a clean URL. If I set the permalinks to 'default' the rule works fine.

Also I disable the default WordPress 301 redirection from adding filter for 'redirect_canonical'.

Suppose my post URL is example.com/2015/03/22/abc-test and I want to write a rule so that if I enter example.com/2015/03/22/custom/abc-test in browser then it should display the content of example.com/2015/03/22/abc-test

Nginx Rule:

location ~* ^(.*)/custom(.*)$ {
    rewrite ^(.*)/custom(.*)$ $1$2 last;
}

I need assistance finding out how Nginx rewrite rules work with WordPress permalink.

2 Answers 2

1

Use this plugin in wordpress and write rule which will overwrite nginx rule.

https://wordpress.org/plugins/rewrite/

When you have wordpress, you have to set permalink to default to work your webserver rule work and if you dont want to do that you have to install above plugin and write rule.

1
  • Suggesting a plugin to do what's possible in the core of the web server quite easily is not very helpful.
    – PKHunter
    Feb 13, 2017 at 3:34
0

Here is a simple Nginx vhost configuration to work with WordPress URL rewriting:

server {
   listen 80;
   server_name example.com;
   root "/var/www/staging/example";
   index index.php;
   location / {
      try_files $uri $uri/ /index.php?$args;
   }

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

}

There is a complete guide on how to configure Nginx with WordPress here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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