Please disable ad blocker to see the page.

WordPress permalinks setting for nginx server

Setting of permalinks is easy when you use Apache server. WordPress core functionality checks for mod_rewrite module and create htaccess file for WordPress permalinks and add the rewrite rules automatically.

Look at the htaccess for url structure.

#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

But when your WordPress is installed on nginx server htaccess file will not work. In Apache you can put htaccess on root directory of the website but nginx not work like that. So how you can do WordPress permalinks setting on nginx server?

There are so many manuals are available on the net one of them is http://centminmod.com/nginx_configure_wordpress.html#basicwordpress.

It uses HttpRewriteModule#rewrite  to rewrite the url and you will have to add the rules manually. Also you will find a differences of syntax between these two server's file.

In most cases when you configure the permalinks from admin the pages will show 404 error (page not found). To solve this issue you need to enter the rewrite rule in nginx configuration file (/etc/nginx/nginx.conf).

The rule will be look like this.

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

or

      index index.php index.html;
      if (!-e $request_filename) {
        rewrite ^/(.+)$ /blog/index.php?q=$1 last;
      }
}

But what if you don't have access of server? In this situation you will have to use your hosting control panel.

Let's see how.

Login to your control panel.



After logged in you will see a list of modules. Click on Sites.


Here you will get hosted sites. Click on the site name for which you need to rewrite the urls.


Now you can see the options to configure that site but you only need one that is Redirect. Click on that you will find a box for rewrite rules.


Enter the rules for WordPress permalinks as below:

if (!-f $request_filename){
set $rule_1 1$rule_1;
}
if (!-d $request_filename){
set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){
rewrite /. /index.php last;
}

If you add rules in the configuration file you will need to restart the configuration but if you add it via cpanel then it will be applied after a minute.
Previous
Next Post »
0 Comment