WordPress
Using Permalinks
Table of Contents
1 Permalink Types
1.1 Default ("Ugly")
1.2 mod_rewrite ("Pretty Permalinks")
1.3 PATHINFO ("Almost Pretty")
2 Structure Tags
3 Where's my .htaccess file?
4 Creating Rewrite Rules (.htaccess)
4.1 Using Permalinks Without mod_rewrite
4.2 Fixing Permalink Problems
4.2.1 Fixing (.htaccess) Generation Issues
4.3 Permalinks, .htaccess, and MS Frontpage
4.3.1 Quick Fixes, Frontpage or Permalinks
4.3.2 Using Frontpage AND Permalinks Together
4.3.3 A Final Note
4.3.4 Long Permalinks
4.3.5 Fixing Other Issues
4.3.6 More Help
5 Tips and Tricks
5.1 Having your posts end in .html
6 External Resources
Permalinks are the permanent URLs to your individual weblog posts, as well as categories and other lists of weblog postings. A permalink is what another weblogger will use to refer to your article (or section), or how you might send a link to your story in an e-mail message. Especially when they are used to link to individual postings, once a story is posted, the URL to it should be permanent, and never change. Hence the "perma" in the name.
Permalink Types
There are three basic types of WordPress permalinks:
Default ("Ugly")
The default looks like http://example.com/?p=N Where N is a number. This is the default for new WordPress installations because it works on all server environments. It is, however, not desired by many people, because it doesn't look as nice as some of the other options.
mod_rewrite ("Pretty Permalinks")
These are the holy grail of permalinks. There are many different formats, but the most common, and most versatile looks like http://example.com/yyyy/mm/dd/post-name/ Some people also eliminate some or all of the date elements (day, month, year) to have a shorter permalink format. mod_rewrite permalinks require Apache's mod_rewrite module, which means that people running other servers cannot use them. See Pretty Permalinks for more info.
PATHINFO ("Almost Pretty")
PATHINFO permalinks look very much like mod_rewrite permalinks but for one exception: they have /index.php inserted before them. Like so: http://example.com/index.php/yyyy/mm/dd/post-name/ Otherwise, they are the same as the "pretty" mod_rewrite permalinks, and are similarly flexible. Anything that mod_rewrite permalinks can do, PATHINFO permalinks can do, with the help of that /index.php part.
Structure Tags
You can use these tags to customize your "Pretty" or "Almost Pretty" permalinks.
These types of permalinks work on most systems without any problems, but there are still some conditions where problems occur.
/%year%/%monthnum%/%day%/%postname%/
Where's my .htaccess file?
The .htaccess file should be in the directory indicated by your "Blog address (URI)" setting on your General Options page. Since the name of the file begins with a ".", the file may not be visible through an FTP client unless you change the preferences of the FTP tool to show all files, including the hidden files.
If you do not already have a .htaccess file, create one. If you have shell, or ssh access to the server, a simple touch .htaccess will create the file. If you are using FTP, create a file on your local computer, call it 1.htaccess, upload it to the root of your WordPress install, and then rename it to .htaccess. Now read the following section to see how you can edit the file.
Creating Rewrite Rules (.htaccess)
Your server must have mod_rewrite for cruft-free permalinks to work. In addition, you must create a .htaccess file and place it in the directory in which your main index.php file resides, or make that directory writable so that WordPress can do this for you. For example, if your WordPress blog is installed at domain.com/wordpress/, put the .htaccess file at domain.com/wordpress/.htaccess. However, if your WordPress installation is in a subdirectory, but your visitors access your site at the top level of your domain, place the .htaccess file at domain.com/.htaccess.
When you create a permalink structure, WordPress will generate rewrite rules and attempt to insert them into the proper .htaccess file. If it can't, it will print the rules out for you to copy and paste into your .htaccess file.
A few notes about creating and editing your .htaccess file:
Using Permalinks Without mod_rewrite
For cruftless permalinks, you must use mod_rewrite, and IIS (common on Windows servers) does not support mod_rewrite. If you are using Apache 2.0.54, on Windows, mod_rewrite may work. If you put a filename at the beginning, WordPress will attempt to use that to pass the arguments and bypass the necessity for mod_rewrite.
/index.php/%year%/%monthnum%/%day%/%postname%/
If you use this option, you can ignore the rewrite rules (that is, you can ignore .htaccess).
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
This reference from Cem via http://blog.taragana.com/index.php/archive/wordpress-tip-on-permalink-options/
Another solution exists using IIS' custom 404 redirects.
It requires that your web host allows you to add a custom 404 redirect, but it doesn't require you to install any 3rd party mod_rewrite software and it also doesn't require that your permalink structure begin with /index.php/...
Here is the link to the installation files and instructions:
http://www.keyboardface.com/IIS-Permalinks/
Fixing Permalink Problems
Fixing (.htaccess) Generation Issues
If your installation of WordPress does not generate a .htaccess file or if it does not write the new rules onto your existing .htaccess file then there are a couple reasons that could be causing this. Work step by step and continue to the next step only if the previous step does not work.
Permalinks, .htaccess, and MS Frontpage
A note about Microsoft Frontpage, many servers (shared and dedicated) maintained and built by various hosting companies come with mod_frontpage compiled with the apache build, and in many cases with the Frontpage Server Extensions installed, on each virtual server. This is more common than not, many/most binary distributions used in the server build process at most hosting companies these days include both mod_fronpage and the server extensions. Even if you're not using Frontpage, because of the way that the extensions interact with apache (and the httpd.conf file) you'll likely get something like a 500 error or blank white page when trying to view your WP install (although the admin panel may operate correctly) simply because the extesions/mod_frontpage exist on your server.
Wordpress will operate correctly with the Frontpage Extensions installed, however permalinks will not function at all and ANY change to the permalinks section from the Wordpress admin interface will cause corruption of the Frontpage server extensions due to the addition of the mod_rewrite rules to the .htaccess file. There is however now a fix for this situation.
Quick Fixes, Frontpage or Permalinks
Frontpage Extensions Fix: If you don't care about permalinks and just want to make the MS Frontpage server extensions work again, simply edit your .htaccess file and remove the wordpress section with the rewrite rules.
To Use Permalinks: If you don't care about Frontpage(but your hosting company has the extensions installed) You will need to remove (or have your hosting company do so) the MS Frontpage server extensions, or simply edit the .htaccess file to removed all of the Frontpage Lines, leaving only the wordpress mod_rewrite code.
Using Frontpage AND Permalinks Together
Finally, A solution.
There have been a number of threads on this issue in the support forums, and until now, no solution to the problem.
Normally, on a Unix server with the Microsoft Frontpage Server extensions installed wordpress works just fine and you are able to edit and publish pages (with MS Frontpage) - UNTIL - you make a change to the permalinks (for example to the date based kind that I like /2005/04/etc). I often suggest that type of URI to folks asking about permalinks etc, as that is the method recommended by the w3c (see http://www.w3.org/Provider/Style/URI ).
Now, the problem is that MS Frontpage uses the .htaccess file (which the wordpress mod_rewrite rules must go into) for it's "publishing" and "web authoring" configuration. As soon as the wordpress mod_rewrite code is added to the file, two things happen - the permalinks don't work, and the MS Frontpage Server extensions become corrupted.
I have tried countless ways to get around this, including trying to use rewrite rules that "ignore" the %{HTTP_USERAGENT)% used by Frontpage, to using a second AccessFilename .wpaccess to the httpd.conf file, and a host of other things, and nothing worked so that a person would be able to both use MS Frontpage to manage the website and use the permalinks for wordpress at the same time.
The solution is acctually quite simple, and I kind of figured it out by accident.
If you are using or wish to use MS Frontpage (or that's just how your hosting company has things configured) along with wordpress you'll need to take the following simple steps on your server (or have your hosting company do it for you).
MS Frontpage creates the following directory _vti_bin
Nested within that it creates both _vti_adm and _vti_aut
In addition to in your website (or wordpress) root folder in all of those directories you will find additional .htaccess files.
In all three of these directories AND in the root directory, at the top of ALL of the .htaccess files you simply need to add one line -
Options +FollowSymlinks
There may or may not already be a line in each like Options None Edit and save each .htaccess file and you're done. Now everyhting works perfectly, including MS Frontpage, AND the permalinks of your choosing.
A Final Note
On a personal note, I prefer to use Frontpage to manage/maintain sites, I've been using it since around '96, and by now, since I do most work on UNIX servers anyway I have it configured to use external editors for just about everything, including Zend Studio for php files, Bradbury TopStyle for stylesheets, Adobe ImageReady/Photoshop for images, etc. I'm more or less just using Frontpage as a convenient way to manage the site and access everything, etc. Then when I hit the "save" button in any of the other applications, they have Frontpage save my changes directly to the server, with no need to be FTP'ing files around, etc. It does help to get lots accomplished very quickly, and I was pretty bummed for the past year or so with the permalink frustration, since I was either needing to not use permalinks or not use Frontpage, or keep re-installing the FP extensions. At one point I found a way to make a .htaccess for my "running" site, but then change it to a FP .htaccess when I was doing any work (permalinks of course didn't work), either way it was a real pain.
This should work with most versions of FP and most of the unix versions of the extensions in use today.
--Chradil 17:24, 17 May 2006 (GMT)
Long Permalinks
When using extra long permalinks in email and posting in comments and chats, some long permalinks are "chopped off" or only the first section is actually recognized as a link and the end seen as text. Here is an example.
Can result in:
To click on the lower link, the user would get a 404 Page Not Found Error. If you have a tendency to use very long permalink post titles, take these steps to prevent this problem.
1. Check that you are indeed using Permalinks.
2. Edit your .htaccess file and add the following and save the file:
RewriteRule ^post/([0-9]+)?/?([0-9]+)?/?$ /index.php?p=$1&page=$2 [QSA]
3. Test it. Find a post's ID number and type the following (with your information) in your browser and you should be redirected to your post:
http://yourdomain.example.com/post/(the ID #)
It is also worth noting that most email software will not cut off URLs that have been delineated with angle-brackets (< and >), so when pasting URLs into emails, you should write them as so:
Fixing Other Issues
If your .htaccess file is being generated correctly, but Permalinks still do not function, the following might be a problem. If problems persist, post a note in the WordPress Forum's (http://www.wordpress.org/support) How To section.
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
You may also have to enable the AllowOverride directive in your DocumentRoot:
<Directory /var/www/html>
# ... other directives...
AllowOverride All
</Directory>
More Help
If these steps do not work, search for your problem in the Codex (http://codex.wordpress.org), Troubleshooting, or in the Support Forum (http://wordpress.org/support/). As a last resort, file a bug report.
Tips and Tricks
Having your posts end in .html
There's an easy way to having your posts end in a .html extension, using the structure tags above. Following the example used on properly terminating permalinks, you could have a page like http://yoursite.com/2006/01/01/happy-newyear.html with this rule:
/%year%/%monthnum%/%day%/%postname%.html
Note that this does not generate actual .html files. It is only an illusion. There is no benefit to this... some people mistakenly think it offers search engine benefits, and some want their permalinks to emulate those of another publishing system.
External Resources
Retrieved from "http://codex.wordpress.org/Using_Permalinks"