WordPress

Using Permalinks

What are Permalinks?

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. See Pretty Permalinks for more info.

Structure Tags

You can use these tags to customize your permalinks.

%year%
The year of the post, four digits, for example 2004
%monthnum%
Month of the year, for example 05
%day%
Day of the month, for example 28
%hour%
Hour of the day, for example 15
%minute%
Minute of the hour, for example 43
%second%
Second of the minute, for example 33
%postname%
A sanitized version of the title of the post. So “This Is A Great Post!” becomes “this-is-a-great-post” in the URI (see note below)
%post_id%
The unique ID # of the post, for example 423
%category%
A sanitized version of the category name. Nested sub-categories appear as nested directories in the URI.
%author%
A sanitized version of the author name.

Note on using only %postname%: If you use postname as the only element in your permalinks to create a structure such as myblog.com/post-title, the rewrite rules may make it impossible to access pages such as your stylesheet (which has a similar format) or the wp-admin folder. It's best to include some numeric data (e.g. the post ID or date) in the permalink to prevent this from happening. Additionally, WordPress v1.2.x requires the use of a date structure in order for some features, such as the calendar, to function properly. /archives/%year%/%monthnum%/%day%/%postname%/ is always a good start.

Note on using %category%: %category% does not work correctly with mod_rewrite in Apache versions prior to 2. If you are using Apache 1, do not use %category% in your permalink structure.

Note on using %category% with multiple categories on a post: Where you assign multiple categories to a post, only 1 can show up in the permalink. This will be the lowest numbered category (see manage categories). The post will still be accessible through all the categories as normal.

Properly terminating permalinks: It's important to guarantee permalinks lead to individual posts within your custom URI, so make sure to end a virtual site structure with either %post_id% or %postname%
EX: /archives/%year%/%monthnum%/%day%/%postname%/

Editing Rewrite Rules (.htaccess)

This is not required when using WordPress v1.5. WordPress v1.5 creates and/or edits the .htaccess file for you.

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. 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 for you to copy and paste into your .htaccess file.

A few cautions about creating and editing your .htaccess file:

Using Permalinks Without mod_rewrite

For permalinks in general, you must use mod_rewrite, and Windows server do not support mod_rewrite. 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.
EX: /index.php/archives/%year%/%monthnum%/%day%/%postname%/

If you use this option, you can ignore the rewrite rules (that is, you can ignore .htaccess).

Linking to Permalinks

To link to a permalink from within your site, such as to another post, use the permalink reference from the root of your site directory with a slash on the end such as:

/wordpress/archives/2005/10/01/specific-postname/

The structure of the link is based upon your permalink structure.

To link to a permalink that "leaves" your site and then returns, you will need the full permalink address, such as:

http://www.mysite.com/wordpress/archives/2005/10/01/specific-postname/

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 step below does not work.

  1. You must chmod the .htaccess file to 666 to edit it with the WordPress template editor, but this is not recommended, since if you do that, any user of your blog, who can edit templates will be able to edit it. You can change the permissions to 660 to make it server-writable, which again will have the same limitation.
  2. Your host might have blocked the SERVER_SOFTWARE variable and this will cause Wordpress's .htaccess generation to fail. If you are sure that your server is running Apache, you can force WP to believe that your server is running Apache by changing your wp-includes/vars.php file. Follow the steps below to implement these changes.
    1. Open the wp-includes/vars.php file using the built in file editor in your WP Admin panel. To navigate to this panel, login to Wordpress, click on "Manage", then on "Files", lastly scroll to the bottom and type in wp-includes/vars.php into the text box under the "Other Files" title.
    2. Look for $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? 1 : 0;, once you find it replace it with // $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? 1 : 0;
    3. Add a new line under // $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? 1 : 0; and type in $is_apache = 1;

Fixing Other Issues

If your .htaccess file is being generated correctly, but Permalinks still do not function, you may have one of these problems.

  1. Your server may not have the AllowOverride directive enabled. If the AllowOverride directive is set to None in your Apache httpd.config file, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem. When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files. Example of enabled AllowOverride directive in httpd.config:

<Directory />
   Options FollowSymLinks
   AllowOverride All
</Directory>

If you don't want to set AllowOverride to all (as it is above) then your AllowOverride list must include the FileInfo directive. You must restart your Apache server for any httpd.config file changes to take effect. For more information on which overrides are allowed, read about Apache Core Features (http://httpd.apache.org/docs-2.0/mod/core.html#allowoverride).

More Help

If these steps do not work, search for your problem in the Codex (http://codex.wordpress.com) or in the Support Forum (http://wordpress.org/support/). As a last resort, file a bug report in the Mosquito (http://mosquito.wordpress.org).

Retrieved from "http://codex.wordpress.org/Using_Permalinks"

This page was last modified 09:32, 30 Mar 2005.


Using Permalinks

Table of contents

1 What are Permalinks?
2 Structure Tags
3 Editing Rewrite Rules (.htaccess)
4 Using Permalinks Without mod_rewrite
5 Linking to Permalinks
6 Fixing (.htaccess) Generation Issues

What are Permalinks?

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. See Pretty Permalinks for more info.

Structure Tags

You can use these tags to customize your permalinks.

%year%
The year of the post, four digits, for example 2004
%monthnum%
Month of the year, for example 05
%day%
Day of the month, for example 28
%hour%
Hour of the day, for example 15
%minute%
Minute of the hour, for example 43
%second%
Second of the minute, for example 33
%postname%
A sanitized version of the title of the post. So “This Is A Great Post!” becomes “this-is-a-great-post” in the URI (see note below)
%post_id%
The unique ID # of the post, for example 423
%category%
A sanitized version of the category name.
%author%
A sanitized version of the author name.

Note on using only %postname%: If you use postname as the only element in your permalinks to create a structure such as myblog.com/post-title, the rewrite rules may make it impossible to access pages such as your stylesheet (which has a similar format) or the wp-admin folder. It's best to include some numeric data (e.g. the post ID or date) in the permalink to prevent this from happening. Additionally, WordPress v1.2.x requires the use of a date structure in order for some features, such as the calendar, to function properly. /archives/%year%/%monthnum%/%day%/%postname%/ is always a good start.

Properly terminating permalinks: It's important to guarantee permalinks lead to individual posts within your custom URI, so make sure to end a virtual site structure with either %post_id% or %postname%
EX: /archives/%year%/%monthnum%/%day%/%postname%/

Editing Rewrite Rules (.htaccess)

This is not required when using WordPress v1.5. WordPress v1.5 creates and/or edits the .htaccess file for you.

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. 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 for you to copy and paste into your .htaccess file.

A few cautions about creating and editing your .htaccess file:

Using Permalinks Without mod_rewrite

For permalinks in general, you must use mod_rewrite. However, if you put a filename at the beginning, WordPress will attempt to use that to pass the arguments.
EX: /index.php/archives/%year%/%monthnum%/%day%/%postname%/

If you use this option, you can ignore the rewrite rules.

Linking to Permalinks

To link to a permalink from within your site, such as to another post, use the permalink reference from the root of your site directory with a slash on the end such as:

/wordpress/archives/2005/10/01/specific-postname/

The structure of the link is based upon your permalink structure.

To link to a permalink that "leaves" your site and then returns, you will need the full permalink address, such as:

http://www.mysite.com/wordpress/archives/2005/10/01/specific-postname/

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 step below does not work.

  1. You must chmod the .htaccess file to 666 to edit it with the WordPress template editor, but this is not recommended, since if you do that, any user of your blog, who can edit templates will be able to edit it. You can change the permissions to 660 to make it server-writable, which again will have the same limitation.
  2. Your host might have blocked the SERVER_SOFTWARE variable and this will cause Wordpress's .htaccess generation to fail. If you are sure that your server is running Apache, you can force WP to believe that your server is running Apache by changing your wp-includes/vars.php file. Follow the steps below to implement these changes.
    1. Open the wp-includes/vars.php file using the built in file editor in your WP Admin panel. To navigate to this panel, login to Wordpress, click on "Manage", then on "Files", lastly scroll to the bottom and type in wp-includes/vars.php into the text box under the "Other Files" title.
    2. Look for $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? 1 : 0;, once you find it replace it with // $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? 1 : 0;
    3. Add a new line under // $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? 1 : 0; and type in $is_apache = 1;

If both of these steps do not work, search for your problem in the Codex (http://codex.wordpress.com) or in the Support Forum (http://wordpress.org/support/). As a last resort, file a bug report in the Mosquito (http://mosquito.wordpress.org).

Retrieved from "http://codex.wordpress.org/Using_Permalinks"

This page was last modified 00:18, 22 Feb 2005.