Skip to content


Pretty Permalinks with Wordpress and Nginx

A permalink is a permanent link to an article or blog entry. Its what you get when a user clicks on the titles of one of your wordpress entries, so if they want to give the link to someone else, the url will always be the same. By default wordpress will make the permalink to the article the articles ID, so it would look like example.com/?p=123, which isn’t very descriptive. Instead if you log into your admin panel and select settings and then permalinks you can change the format of your links to something a little more human readable, and much more search friendly such as http://www.thinkbohemian.com/2010/01/29/national-instruments-extreme-video/ which tells you not only the date it was published but the title too.

You may find after you’ve changed your permalinks that your articles now all get a 404 error. This is because your server thinks that your looking for a file in the /2010/01/29/national-instruments-extreme-video/ directory. So we need to let our server know not to do that. There are plenty of examples of how to do the re-write if you’re using apache, but if you’re an nginx fanboy like I am, there wasn’t very much information. So to make this happen we need to add a few extra lines under our nginx.conf under the location / { section like this:

       location / {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
         }
        }

Enjoy the pretty permalinks!!

Update:

Posted in Web Development, systems administration. Tagged with , , , , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.