Pretty URLs in WordPress

If you’re a new WordPress user, you may have noticed that some WordPress blogs have “pretty URLs” with the date and the name of the post in the path. It’s not hard to set it up and you can have URLs such as “yourdomain.com/archives/2005/04/21/post-name/” . (In addition to the aesthetics, this also lends to higher search engines rankings as search engines consider a link’s path relevant.)

So, how does it work? Well, “permalinks” are set up through the options in WordPress and all the magic happen behind-the-scenes through virtual URLs on the server (so don’t worry about having to create all those directories manually). But before setting the options, you’ll first need to prep a file which is called “.htaccess” (yeah, it’s a a filename with only an extension, which probably seems weird if you're running Windows). You’ll need to make sure that it exists on your web host and, if not, you’ll need to create a blank version first…

To do that, log in to your web host (such as with ftp or ssh) and check to see if a file called .htaccess exists in your web root (which is the directory on your web host corresponding to the root directory of your domain). And, if the file is already there, you can skip the next sentence. But, if not, no worries — just create a blank version of the file (such as by opening Notepad or TextEdit and immediately saving it without typing anything) and upload that to your web root. And, with the file in place, you’ll need to set its permissions to 666 (which is probably done through the context menu of your ftp client with an option called “permissions” or “chmod”).

After that, you'll need to load the WordPress admin interface (at www.yourdomain.com/wp-admin/) and go to Options -> Permalinks (or just go directly to the URL www.yourdomain.com/wp-admin/options-permalink.php). There, you’ll need to enter what structure you’d like for your permalinks, which most people set to include the link’s date and post name along with an optional prefix directory such as “archives”. That’s a format that I like and if you’d like to use that, just enter this in the Structure field on that page:

/archives/%year%/%monthnum%/%day%/%postname%/

Then, it's just a matter of clicking the submit button on that screen (which, on my WordPress setup reads “Update Permalinks”, but it might read slightly differently on yours). And, if you're running WordPress 1.5, that should be all there is to it. However, if you’re using WordPress 1.2, you may be presented with a block of text for your .htaccess file; in that case, just copy-n-paste that into the empty .htaccess file on your hard drive and upload that to your web root. Either way, WordPress will let you know if this step is necessary — so, if you hit the submit button and you’re not presented with a block of text, then you don’t need to worry about it.

If this didn’t work out for you, I’d first recommend checking that the permissions on your .htaccess file were set correctly. And, if that looks good, I’d check to make sure that your web host offers mod_rewrite (which is the Apache that provides all this permalink goodness). There’s also a section on permalink troubleshooting in the WordPress wiki. But, don’t let this paragraph scare you — chances are, it’ll work just fine :).

One thought on “Pretty URLs in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.