Suffered by wordpress permanent links in nginx

November 4, 2011 by · Comments Off on Suffered by wordpress permanent links in nginx
Filed under: linux, server 

I installed wordpress several month ago by default. The page links were in default format like /blog/p?101. After some posts written I realized that these format is not friendly to search engine. So I decided to change the permalinks format in wordpress. It is a suffered experience.

After I changed the permalinks to custom structure, such as “/%year%/%monthnum%/%day%/%postname%/”, then some pages, and the category, tags links, pages could not be visited correctly.

And I tried install the WP plugin “advanced permalinks”. The plugin’s feature sounds very promising, it can reserve your old pages’ permalinks in an different structure. But after activated, some of my links (like category, tags) broken too.

Then I added configurations in nginx.conf, with lots of location definitions …. :

77                 location /blog/2011 { ### for nginx redirection, 2011/06
 78                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 79                 }
 80                 location /blog/category { ### for nginx redirection, 2011/06
 81                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 82                 }
 83                 location /blog/feed{ ### for nginx redirection, 2011/06
 84                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 85                 }
 86                 location /blog/comments{ ### for nginx redirection, 2011/06
 87                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 88                 }
 89                 location /blog/sample-page{ ### for nginx redirection, 2011/06, About me
 90                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 91                 }

 95                 location /blog/index.php{ ### for nginx redirection, 2011/06
 96                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;

…. Each time a new kind of url(which has the same prefix) I added a location config, it is difficult and boring to maintenance the file.

Even more worse, when I installed a new wordpress plugin, the configuration page is in a new url, it couldn’t be accessed.

Oh my god, finally, I changed the nginx.conf like this (leave a catch-all entry in the end), then pages are shown without any colors and styles except black and white…

 77                 location /blog/2011 { ### for nginx redirection, 2011/06
 78                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 79                 }
 80                 location /blog/category { ### for nginx redirection, 2011/06
 81                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 82                 }
 83                 location /blog/feed{ ### for nginx redirection, 2011/06
 84                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 85                 }
...
 92                 location /blog/index.php/category{ ### for nginx redirection, 2011/06
 93                   try_files $uri $uri/ /blog/index.php/?q=$uri&$args;
 94                 }
 95                 location /blog/index.php{ ### for nginx redirection, 2011/06
 96                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
 97                 }
 98                 location /blog/{ ### for nginx redirection, 2011/06
 99                   try_files $uri $uri/ /blog/index.php?q=$uri&$args;
100                 }

 

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)