WordPress static links based on Nginx

 · 1 min read

wordpress’s default linking style is dynamic form, like:

xxx/?pageid=8

into

xxx/pageid/8

Doing this is reader-friendly, and makes url look more elegent, but most important is helping search engine to understand so that your archives could be easily collected.

No more garbage, let’s do it!


  1. go into wp setting->permalinks, change it into /%category%/%post_id%/ like this:

    PS: after that, your archives would render 404 to users immediately, don’t worry</p>

  2. modify nginx config

    In case someone doesn’t know where the config file is, input nginx -t</p>

root@me:/usr/local/nginx/conf# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

open nginx.conf, add these below:

location / {  
       index index.html index.php;  
       if (-f $request_filename/index.html){  
           rewrite (.*) $1/index.html break;  
       }  
       if (-f $request_filename/index.php){  
           rewrite (.*) $1/index.php;  
       }  
       if (!-f $request_filename){  
           rewrite (.*) /index.php;  
       }  
   }  
  1. restart nginx, enjoy it!
nginx -s reload

about more config of nginx, visit here:

nginx#location