<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digging into WordPress &#187; permalink</title>
	<atom:link href="http://digwp.com/tag/permalink/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Smarter Slugs ~!@$%^&amp;*()={}[]?</title>
		<link>http://digwp.com/2012/01/smarter-slugs/</link>
		<comments>http://digwp.com/2012/01/smarter-slugs/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 19:39:26 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[permalink]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5620</guid>
		<description><![CDATA[See those crazy characters in the title of this post? Now see how they don&#8217;t appear in the post&#8217;s URL? That&#8217;s one of the finer details of the WordPress 3.3 update: smarter permalink slugs. So when you type something like you see in the title of this post, with all the funky characters, or even [...]]]></description>
			<content:encoded><![CDATA[<p>See those crazy characters in the title of this post? Now see how they <em>don&#8217;t</em> appear in the post&#8217;s URL? That&#8217;s one of the <em>finer details</em> of the WordPress 3.3 update: <strong>smarter permalink slugs</strong>.</p>
<p><span id="more-5620"></span></p>
<p>So when you type something like you see in the title of this post, with all the funky characters, or even just something like a comma, apostrophe, or semi-colon, WordPress 3.3+ works the magic and automatically creates your post slug without the junk. </p>
<h3>Details.</h3>
<p>It may not seem like a big deal, but previous versions of WordPress would include those funky characters when auto-creating your permalink slugs. If you glance at URLs while surfing around WordPress-powered sites, keep an eye on the URL in the address bar. It&#8217;s common to see all sorts of non-alphanumeric stuff in there.</p>
<p>Does it matter? I think so, for numerous reasons:</p>
<ul>
<li><strong>Readability, consistency</strong> &ndash; simple alphanumeric URLs work great everywhere, no need to clutter them up with redundant information. For example, funky characters can choke URL-shortening services. Also: fewer characters, facilitates better comprehension.</li>
<li><strong>Safer</strong> &ndash; certain characters such as <code>`</code>, <code>^</code>, <code>"</code>, <code>~</code>, <code>#</code>, <code>%</code>, <code>|</code>, <code>\</code>, <code>&lt;</code>, <code>&gt;</code>, <code>"</code>, <code>~</code>, <code>[</code>, <code>]</code>, <code>{</code>, <code>}</code>, and the blank space are considered as unsafe and should not be included in the URI (ie., always need encoded). Including them may seem to work, but you&#8217;re introducing sort of unknown variable into the mix, a potential vulnerability<a href="#ref" title="Jump to reference link">*</a></li>
<li><strong>SEO</strong> &mdash; do funky characters like blank spaces and percentage signs in the URL <em>hurt</em> your site&#8217;s SEO? Maybe not, but why put anything in there that <em>isn&#8217;t</em> a keyword?</li>
</ul>
<p>So smarter auto-slugs in WordPress 3.3, another one of the <em>finer details</em> that improves the overall WP post-editing experience, and something you may not have noticed.</p>
<h3>Bonus tip</h3>
<p>Another sort of related &ldquo;smarter-slugs&rdquo; feature noticed while looking into it, is the automatic removal of the &ldquo;-2&rdquo; that WordPress automatically appends to the post slug when a duplicate is detected. So for example, say you&#8217;re working on a new post:</p>
<ol>
<li>Create a post with a slug such as &ldquo;<code>test-post</code>&rdquo;</li>
<li>Delete the post and send to the Trash</li>
<li>Create another post with the same &ldquo;<code>test-post</code>&rdquo; slug</li>
<li>WordPress detects the duplicate post in the database and appends a &ldquo;-2&rdquo;, like so: <code>test-post-2</code> to the post slug</li>
<li>Create yet another post with the same slug and WordPress will append a &ldquo;-3&rdquo;, and so on..</li>
</ol>
<p>Nobody likes the &ldquo;dash-twos&rdquo; but they are required for the auto-creation of non-duplicate post slugs. What I just noticed with version 3.3 is that, once you empty the Trash, <strong>WordPress automagically removes the &ldquo;-2&rdquo; from the post slug</strong>, improving workflow to save you time. This may have changed in a previous version and I just hadn&#8217;t noticed, or it&#8217;s another one of the <em>administrative refinements</em> of WordPress 3.3.</p>
<p><strong>Update:</strong> it looks like the -2 removal only applies to <strong>drafts</strong> and <strong>pending</strong> posts, not to posts that have already been published.. (see <a href="#comment-32497">comment from Otto</a>)</p>
<p id="ref"><strong>*</strong> More info on <a href="http://perishablepress.com/press/2009/03/08/building-the-perishable-press-4g-blacklist/" title="Building the Perishable Press 4G Blacklist">forbidden characters and blocking them</a></p>
<hr />
<p><small>© 2012 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2012/01/smarter-slugs/">Permalink</a> | <a href="http://digwp.com/2012/01/smarter-slugs/#comments">16 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2012/01/smarter-slugs/&title=Smarter Slugs ~!@$%^&#038;*()={}<>[]?">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/permalink/" rel="tag">permalink</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2012/01/smarter-slugs/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>New htaccess Code for WordPress Permalinks</title>
		<link>http://digwp.com/2011/01/new-htaccess-permalink-rules/</link>
		<comments>http://digwp.com/2011/01/new-htaccess-permalink-rules/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 18:21:57 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[HTAccess]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[permalink]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3555</guid>
		<description><![CDATA[While manually upgrading a bunch of old WordPress sites, I realized that the WordPress htaccess rules for permalinks had changed. For many years and versions, the htaccess code that enables WordPress permalinks went unchanged, resulting in an almost sacred set of htaccess directives. Here are the original permalink rules as currently provided at the WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>While manually upgrading a bunch of old WordPress sites, I realized that the <a href="http://perishablepress.com/press/2006/06/14/the-htaccess-rules-for-all-wordpress-permalinks/" title="WordPress HTAccess Permalink Rules">WordPress htaccess rules for permalinks</a> had changed. For many years and versions, the htaccess code that enables WordPress permalinks went unchanged, resulting in an almost sacred set of htaccess directives. Here are the <em>original</em> permalink rules as currently provided at the <a href="http://codex.wordpress.org/Using_Permalinks">WordPress Codex</a>:</p>
<p><span id="more-3555"></span></p>
<pre><code># BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
# END WordPress</code></pre>
<p>When working with WordPress, that snippet is the <em>only</em> htaccess code that is actually <em>required</em> by WordPress, and even then, it&rsquo;s only necessary if you are using so-called &ldquo;pretty-permalinks&rdquo; on your site. Needless to say, there are probably <em>millions</em> of instances of these original permalink rules in place on servers and sites all across the Web. The code is so familiar that many WordPress devs can probably write it from memory. So changing things is actually kind of a big deal.</p>
<h3>The NEW WordPress Permalink Rules</h3>
<p>There&rsquo;s really no reason to get all excited about anything. I just tend to get hyped up for anything relating to <a href="http://perishablepress.com/press/tag/wordpress/" title="WordPress Archive at Perishable Press">WordPress</a> or <a href="http://perishablepress.com/press/tag/htaccess/" title="HTAccess Archive at Perishable Press">htaccess</a>. So mix them together and I&rsquo;m all over it. For the <em>new</em> WordPress permalink rules, <strong>only a single line was added</strong>, and it&rsquo;s a good one to have in there:</p>
<p><code>RewriteRule ^index\.php$ - [L]</code></p>
<p>So that&rsquo;s the new hotness, and it works great at what it does, which we&rsquo;ll get to here in a moment. For now, let&rsquo;s go ahead and add that new directive to our <em>original</em> htaccess ruleset to get the <strong>new WordPress permalink rules</strong>:</p>
<p>For sites installed in <strong>root directory:</strong></p>
<pre><code># BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
# END WordPress</code></pre>
<p>And for sites installed in a <strong>subdirectory</strong>:</p>
<pre><code># BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]
&lt;/IfModule&gt;
# END WordPress</code></pre>
<p>I&rsquo;m not sure exactly <em>when</em> the htaccess permalink rules were changed, and I&rsquo;m not sure it really matters, but I&rsquo;m thinking it happened sometime between versions 3.0.0 and 3.0.4. I didn&rsquo;t notice it until version 3.0.4, but I am guessing that it happened at 3.0. Somebody let me know that I&rsquo;m wrong here.</p>
<h3>So what does it do?</h3>
<p>What is the purpose of the new htaccess directive? Why change something that has worked so well for so long? Better have a good reason to go tampering, right? Yes, and as it turns out, this new rule is involved with canonicalization [1] of your WordPress <abbr title="Uniform Resource Locator">URL</abbr>s. I don&rsquo;t think it was by any means <em>necessary</em>, but it&rsquo;s definitely an improvement over the original code. The new directive basically strips off any dangling <code>index.php</code> from your WordPress permalinks.</p>
<p>[1] Update: As <a href="http://digwp.com/2011/01/new-htaccess-permalink-rules/#comment-15831">Robert points out</a>, the new line of code is there to fix an issue with Apache&rsquo;s <code>mod_rewrite</code>; it has nothing to do with canonicalization, which is handled automatically by WordPress.</p>
<p>For example, with the original permalink rules (and no other htaccess modification), the following <abbr title="Uniform Resource Locator">URL</abbr>s all refer to the same page:</p>
<ul>
<li><code>http://digwp.com/</code></li>
<li><code>http://digwp.com/index.php</code></li>
<li><code>http://www.digwp.com/index.php</code></li>
</ul>
<p>Fortunately, WordPress already handles the <code>www</code> canonicalization, and so the new line of htaccess takes care of the <em>other end</em> of the <abbr title="Uniform Resource Locator">URL</abbr>: the <code>index.php</code>. This may not seem like a big deal, but can have a big impact on script performance, search-engine optimization, and user-experience.</p>
<h3>Updating your htaccess rules</h3>
<p>So the question now is &ldquo;do I need to go back and add this new directive to my existing permalink rules?&rdquo; I think the best answer is that you don&rsquo;t <em>need</em> to do anything &ndash; your WordPress-powered sites will continue to work just fine. But if you <em>want</em> the additional canonicalization that the new rule provides, then you probably should stick it in there.</p>
<p>A couple of things to keep in mind about the new htaccess code:</p>
<ul>
<li>No need to update <em>existing</em> htaccess files unless you want to</li>
<li>As with the original code, the new htaccess works in <em>all</em> versions of WordPress</li>
<li>If you do add the new line, make sure to remove/adapt any similar/related htaccess rules</li>
</ul>
<p>For example, as I was going through and updating all of those old sites, I had been using my own recipe for proper <a href="http://perishablepress.com/press/2007/10/01/htaccess-combo-pack-wordpress-permalinks-and-non-www-redirect/" title="WordPress HTAccess Canonicalization Combo Pack">permalink canonicalization</a>:</p>
<pre><code># CANONICAL WP RULES
&lt;IfModule mod_rewrite.c&gt;
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php [NC]
 RewriteRule ^index\.php$ http://example.com/ [R=301,L]
 RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
 RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
&lt;/IfModule&gt;</code></pre>
<p>This code works on <em>any</em> site &ndash; not just WordPress installs &ndash; to clean up both ends of the <abbr title="Uniform Resource Locator">URL</abbr>: the <code>www</code> and the <code>index.php</code>. As I updated my htaccess files with the new WordPress permalink rules, I had to remove this custom canonicalization code to make room (functionally speaking) for the new stuff, which is a much more elegant solution.</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/01/new-htaccess-permalink-rules/">Permalink</a> | <a href="http://digwp.com/2011/01/new-htaccess-permalink-rules/#comments">28 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/01/new-htaccess-permalink-rules/&title=New htaccess Code for WordPress Permalinks">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/htaccess-2/" rel="tag">htaccess</a>, <a href="http://digwp.com/tag/permalink/" rel="tag">permalink</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/01/new-htaccess-permalink-rules/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Optimizing WordPress Permalinks</title>
		<link>http://digwp.com/2010/07/optimizing-wordpress-permalinks/</link>
		<comments>http://digwp.com/2010/07/optimizing-wordpress-permalinks/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 08:45:19 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[permalink]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2026</guid>
		<description><![CDATA[Configuring your WordPress permalinks is simple and only takes a second, but understanding what they are and how they work is key to setting up the best permalink structure possible. Your site&#8217;s permalinks are like the street address for your site&#8217;s web pages. They help both people and robots understand your site&#8217;s structure and navigate [...]]]></description>
			<content:encoded><![CDATA[<p>Configuring your <strong>WordPress permalinks</strong> is simple and only takes a second, but understanding what they are and how they work is <em>key</em> to setting up the <strong>best permalink structure possible</strong>. Your site&rsquo;s permalinks are like the street address for your site&rsquo;s web pages. They help both people and robots understand your site&rsquo;s structure and navigate its contents. There is no &ldquo;one magic permalink recipe to rule them all,&rdquo; but keeping a few tips in mind makes it <em>easy</em> to <strong>optimize your WordPress permalinks</strong>. This <abbr title="Digging into WordPress">DiW</abbr> article shows you how..</p>
<p><span id="more-2026"></span></p>
<h3>WordPress makes it <em>so</em> easy</h3>
<p>WordPress gives you full control over your permalinks. First, you have control over the <em>general structure</em> of your permalinks. Navigate to <strong>Settings &gt; Permalinks</strong> and you will see several options for configuring your permalinks:</p>
<p><img src="http://digwp.com/wp-content/blog-images/optimize-permalinks-setting.gif" alt="[ Screenshot: WP Permalink Settings ]" title="WordPress provides control over the general structure of your permalinks" /></p>
<p>This is where you configure the general structure of your permalinks, as seen here with green underline. The portion underlined in red is post/page-specific, and will vary depending on your individual posts and pages. For <a href="http://digwp.com/" title="Digging into WordPress">DigWP.com</a>, we chose the &ldquo;month and name&rdquo; format, which creates the following permalinks according to page-view:</p>
<ul>
<li><strong>Pages</strong> &rarr; <code>http://digwp.com/about/</code></li>
<li><strong>Tag Archives</strong> &rarr; <code>http://digwp.com/tag/permalinks/</code></li>
<li><strong>Category Archives</strong> &rarr; <code>http://digwp.com/category/seo/</code></li>
<li><strong>Single Posts</strong> &rarr; <code>http://digwp.com/2010/05/wordpress-json-api-plugin/</code></li>
</ul>
<p>..and so on. The main thing that you want to optimize at this point is the structure of your single-post permalinks. We chose to include the year and month for our posts, but it has been argued that it is better to omit the date entirely, using a &ldquo;Custom structure&rdquo; like so:</p>
<p><code>/%postname%/</code></p>
<p>This simple structure will produce single-post permalinks that include only the post name:</p>
<p><code>http://digwp.com/wordpress-json-api-plugin/</code></p>
<p>Without the additional date information, this structure is definitely shorter and cleaner, but there may be <a href="http://dougal.gunters.org/blog/2009/02/04/efficient-wordpress-permalinks" title="Efficient permalink strategies for WordPress">performance issues involved with using the &ldquo;name-only&rdquo; permalink format</a>. Perhaps a good trade-off is to include either the post ID or the year:</p>
<pre><code>/%post_id%/%postname%/
/%year%/%postname%/</code></pre>
<p>I think either of these formats is probably an optimal way to configure your permalinks, but you also want to consider the frequency with which you&rsquo;ll be posting content. It may be beneficial to further organize/classify your posts by including the month and day as well. </p>
<p>Certain &ldquo;experts&rdquo; will tell you that including extraneous date information is bad for <acronym title="Search Engine Optimization">SEO</acronym>. The thinking here is that shorter <acronym title="Uniform Resource Locator">URL</acronym>s correspond to a more &ldquo;flat&rdquo; directory structure, which <a href="http://www.seomoz.org/blog/whiteboard-friday-flat-site-architecture" title="Whiteboard Friday - Flat Site Architecture">may provide some SEO benefits</a>. I think the key is to use what&rsquo;s necessary and omit any extraneous information.</p>
<h3>Post/page-specific permalink structures (slugs!)</h3>
<p>Once you&rsquo;ve defined the <em>general</em> permalink structure in the WordPress Admin, you now have full control over your post-specific and page-specific permalink structures (as seen in the above screenshot, red underline). The part of your permalinks that is specific to each page or post is set in the <strong>Write/Edit Post</strong> screen in the WordPress Admin.</p>
<p><img src="http://digwp.com/wp-content/blog-images/optimize-permalinks-slugs.gif" alt="[ Screenshot: WordPress Post Slugs ]" /></p>
<p>As shown in the above screenshot, WordPress provides an &ldquo;Edit&rdquo; button that enables you to modify the post-specific portion of your permalinks:</p>
<p><img src="http://digwp.com/wp-content/blog-images/optimize-permalinks-slugs-e.gif" alt="[ Screenshot: Editing Post Slugs ]" /></p>
<p>This feature enables you to customize your post/page-specific permalinks (also known as a post &ldquo;slug&rdquo;) according to your current permalink optimization strategy. Here are a few examples of commonly employed &ldquo;post-slug&rdquo; strategies:</p>
<dl>
<dt>Don&rsquo;t even worry about it</dt>
<dd>Just let WordPress generate the post-specific slug based on the post or page title. Pros: this is certainly the easiest method of creating permalinks because no thought or action is required. Cons: depending on your post title, you could get some pretty long permalinks that look awkward and sloppy.</dd>
<dt>Remove extraneous words, leave only keywords</dt>
<dd>I have seen lots of blogs do this. It basically involves using the permalink that WordPress generates based on your title, then going in and removing words like &ldquo;the&rdquo;, &ldquo;and&rdquo;, and &ldquo;you&rdquo;, as well as other pronouns and such. Basically the idea is to leave only keywords in your permalinks. This helps keep them short, focused, and optimized for the search engines.</dd>
<dt>Customize every permalink with optimized keywords</dt>
<dd>This is the most labor-intensive strategy, but also potentially the most lucrative in terms of return on investment. The idea here is to research or otherwise understand which keywords your page is going to rank for, and then crafting a post-specific permalink structure based on those keywords. I have seen cases where this is taken to such an extreme that the post slug is completely different than the original post title.</dd>
</dl>
<p>The same goes for both posts and pages, regardless of which method you choose. Personally, I employ a combination of the first two strategies, whereby I go in, write a title, and then look at it and see if there is anything that could be improved. Usually there are several words that need to go, and possibly a keyword or two is added or removed. It&rsquo;s funny because I usually end up rewriting some of the post content after spending some time actually thinking about what to name it. </p>
<blockquote><p>There is always a better title than the one you think should be used.</p></blockquote>
<p>The take-home message here is that, by paying attention to post titles and permalinks, you benefit from improved relevancy and potential <acronym title="Search Engine Optimization">SEO</acronym> advantage.</p>
<h3>Think of your users</h3>
<p>When visitors land on your page, does the <acronym title="Uniform Resource Locator">URL</acronym> make sense? Does it correlate with the page title? These are some of the things to think about while setting up the general structure and post-specific slugs for your permalinks. Look at the permalink and ask yourself if it makes complete sense based on what the user will be looking at on the page. If you get too carried away with optimization, a user may get a sense that something isn&rsquo;t quite right. Perhaps the post title says something like:</p>
<p><strong>The Best Name-Brand Shoes</strong></p>
<p>..but then the post slug looks something like this:</p>
<p><code>http://example.com/nike-adidas-reebok-zip-converse-shoes/</code></p>
<p>Perhaps a weak example, but it serves to illustrate the semantic gap that may occur when over-thinking your permalinks.</p>
<h3>Think of the search engines</h3>
<p><em>After</em> considering your users, think about what the search engines are going to see when they come crawling your pages. Does the permalink match the content of the page? If you aren&rsquo;t bothering with changing or optimizing your post slugs, then the answer is probably yes because WordPress generates the slug from the post title.</p>
<p>Also, as mentioned previously, some have argued in favor of a more &ldquo;flat&rdquo; directory structure in order to improve the <acronym title="Search Engine Optimization">SEO</acronym> value of your blog. Whether or not this is actually the case is up for discussion, but it always makes sense to keep things as simple and concise as possible. So when deciding on the general structure for your permalinks, ask yourself if you really need a directory structure that is over three levels deep, like this:</p>
<pre><code>domain/
	2010/
	      01/
		  1/
			post-slug-1
			post-slug-2
			post-slug-3
		  2/
			post-slug-4
			post-slug-5
			post-slug-6
		  3/
			post-slug-7
			post-slug-8
			post-slug-9
	      .
	      .
	      .
	2011/
	2012/</code></pre>
<p>That&rsquo;s going to give you some <em>long</em> permalinks, especially if you just use the default WordPress-generated slugs. When you look at a permalink using &ldquo;<code>year/month/name</code>&rdquo; format, you are essentially creating a virtual folder structure with a subdirectory for each part of the permalink &ndash; the year represents a directory in which you have a bunch of directories for each month, and within each of those directories there could be as many as 31 subdirectories for each day of the month. Then, within each day of the month, you have the post file itself, which may involve further subdirectories when paging is used. It can get crazy pretty quickly, and even though these subdirectories only exist virtually, to a search spider, there is no practical difference between <em>virtual</em> directories that are deeply nested and <em>actual</em> directories that are deeply nested.</p>
<p>When deciding on your permalink structure, ask yourself if you really need the date built into your permalinks. If you are posting prolifically, then you may want to include the date to help keep things organized. Anything less than a few posts a week, and I would opt to go with something simpler, like maybe &ldquo;<code>year/post</code>&rdquo; or &ldquo;<code>id/post</code>&rdquo;, as mentioned above.</p>
<p>Another thing that needs considering is the notion of &ldquo;evergreen content&rdquo;, which generally refers to content that is intended to stay &ldquo;fresh&rdquo; or relevant forever. Regardless how silly this <acronym title="Search Engine Optimization">SEO</acronym> idea happens to be, you may want to consider either omitting or including some sort of date information based on how easily you want the publication date to be recognized by your visitors. I.e., if you are trying to &ldquo;hide&rdquo; the post date in hopes that your content will rank for a longer period of time, then you should omit it from the general permalink structure. Conversely, if you aren&rsquo;t that slimy and want to make it easy for people to know when the post was produced, then throw a year or year/month into the mix. Whatever!</p>
<h3>Think simplicity</h3>
<p>When it comes to organizing the content of your site, <strong>there is a fine balance</strong> between being <em>well-organized</em> and keeping things <em>simple</em>. For example, the simplest structure would involve all posts and pages directly under the root domain. Clean and simple, but as time goes on and your post count gets into the hundreds or thousands, it could be a drag trying to sort through everything in a flat directory structure. Thus, another reason why breaking things down into categories or dates may help your long-term organizational and maintenance strategy.</p>
<p>For the post-specific portion of the permalinks (the post slug), it is also wise to keep things simple, but not at the risk of duplicating post names. For example, if you are writing a post about jQuery, you might have a post slug that is simply &ldquo;<code>jquery</code>&rdquo;, but it&rsquo;s not going to be very helpful. First, it probably will never rank for that term. Second, telling users that the article is about &ldquo;jQuery&rdquo; is about as useless as it gets for both people <em>and</em> machines. So although that would be the simplest permalink possible, it is your interest to specify a little more clearly the content of your post. It just makes everything easier when meaning is readily available from your permalinks.</p>
<h3>Do it <em>before</em> posting</h3>
<p>Once you hit the &ldquo;Publish&rdquo; button, there is <strong>one</strong> thing that you shouldn&rsquo;t change: the post slug. After publishing a post, you can easily and without consequence go back and change the title, meta title, post content, and just about everything else. But as soon as you change that permalink, you will need to 301 redirect the former <acronym title="Uniform Resource Locator">URL</acronym> to the new one in order to avoid perpetual 404 errors now and in the future. But, if you do need to change the permalink <em>after</em> posting, here is a simple line of <acronym title="Hypertext Access">HTAccess</acronym> to help you eliminate any potential 404 errors:</p>
<pre><code>Redirect 301 /old-post-slug/ http://example.com/new-post-slug/</code></pre>
<p>So it&rsquo;s really very simple: we first call the redirect directive, declare it as status 301 (permanent), and then add the old slug followed by the new one. That line will redirect any requests for your previously &ldquo;slugged&rdquo; <acronym title="Uniform Resource Locator">URL</acronym> to your new <acronym title="Uniform Resource Locator">URL</acronym>. For more information on htaccess redirects, check <a href="http://perishablepress.com/press/2008/12/31/redirect-all-broken-links-from-any-domain-via-htaccess/" title="Redirect All (Broken) Links from any Domain via HTAccess">here</a> and <a href="http://perishablepress.com/press/2008/08/12/redirect-all-requests-for-a-nonexistent-file-to-the-actual-file/" title="Redirect All Requests for a Nonexistent File to the Actual File">here</a>.</p>
<h3>Think of the keywords</h3>
<p>As discussed, a great way to create focused, relevant permalinks is to remove the fluff and include only the important keywords. Granted, Google et al may already discount simple words such as &ldquo;if&rdquo;, &ldquo;and&rdquo;, and &ldquo;the&rdquo;, but you may also have keywords for which you don&rsquo;t necessarily want to rank. For example, if you published a post on why Batman is terrible at website design, you may wind up with a auto-generated post slug like this:</p>
<p><code>batman-sucks-at-website-design</code></p>
<p>The word &ldquo;at&rdquo; should probably go, leaving this:</p>
<p><code>batman-sucks-website-design</code></p>
<p>But you may want to rank primarily for the term &ldquo;website-design&rdquo;, while &ldquo;batman&rdquo; is merely anecdotal, used as example, or whatever. Chances are low that anybody is searching for &ldquo;batman website design&rdquo;, but you never know.</p>
<h3>WordPress removes stuff too</h3>
<p>It should also be noted that WordPress removes certain things from your post/page slugs as well. Namely, any punctuation that is included in your post titles will be removed when WordPress automatically generates the post slug. This is both a good thing and a bad thing, depending on how you look at it. There are certain characters that are not allowed in <em>any</em> <acronym title="Uniform Resource Locator">URL</acronym>, so WordPress is wise to remove them for you. On the downside, removal of punctuation and the use of hyphens as replacements for periods can leave you with some rather odd-looking permalinks. For example, when writing about the latest WordPress update, say version 3.1 specifically, writing this as your title:</p>
<p><code>Introducing WordPress 3.1</code></p>
<p>..will give you this as the default post slug:</p>
<p><code>/introducing-wordpress-3-1/</code></p>
<p>..which to me just looks incorrect, like somebody wasn&rsquo;t paying attention. Moral of the story: even if you&rsquo;re too lazy to optimize your permalink slugs, it is <em>wise to be mindful</em> of what&rsquo;s going on with the auto-generated stuff. In this regard, the WordPress devs made an excellent decision when they decided to move the permalink edit box to just below the post title. I do think it could be a little longer though. Most of the time you need to scroll sideways a bit to see what the entire permalink is looking like.</p>
<h3>WordPress short URLs</h3>
<p>What about Twitter-friendly &ldquo;shortlinks&rdquo; for your posts? Generally even the shortest permalink is going to be too long for tweeting, posting, sharing, etc. There are <a href="http://perishablepress.com/press/2009/10/18/stupid-twitter-tricks/" title="Stupid Twitter Tricks">many ways to create short links</a>, but WordPress actually has <em>two</em> built-in ways to create and display short <acronym title="Uniform Resource Locator">URL</acronym>s. Let&rsquo;s take a look at each:</p>
<p>First is the &ldquo;old&rdquo; way of doing it. By default, WordPress uses a query-string format for your <acronym title="Uniform Resource Locator">URL</acronym>s. As discussed throughout this article, most WordPress users opt for the &ldquo;pretty&rdquo; permalinks instead of going with the &ldquo;ugly&rdquo; default <acronym title="Uniform Resource Locator">URL</acronym>s. But even when permalinks are used, WordPress still understands the default query-string <acronym title="Uniform Resource Locator">URL</acronym> structure, so you can include short links in your posts by doing something like this:</p>
<pre><code>&lt;?php echo get_bloginfo('url')."/?p=".$post-&gt;ID; ?&gt;</code></pre>
<p>Shortlinks have become so common that <a href="http://codex.wordpress.org/Function_Reference/the_shortlink" title="Function Reference/the shortlink">WordPress 3.0 now includes</a> a built-in template tag for this very purpose. All you need to display shortlinks in WordPress 3 and above is include the following code in your theme template file(s):</p>
<p><code>&lt;?php the_shortlink('link text', 'link title', 'before link', 'after link'); ?&gt;</code></p>
<p>Either of these methods will output a link with the following <acronym title="Uniform Resource Locator">URL</acronym> structure:</p>
<p><code>http://example.com/?p=77</code></p>
<p>Also note that WordPress 3.0 now includes a shortlink in the <code>&lt;head&gt;</code> section of your posts and pages, something like this:</p>
<p><code>&lt;link rel='shortlink' href='http://example.com/?p=77' /&gt;</code></p>
<p>This is in <em>addition</em> to the canoncial link tag that is also included in the <code>&lt;head&gt;</code> section.</p>
<h3>WordPress canonical links</h3>
<p>WordPress canonical <acronym title="Uniform Resource Locator">URL</acronym>s are included in the <code>&lt;head&gt;</code> section of your posts and pages. They look like this:</p>
<p><code>&lt;link rel='canonical' href='http://example.com/post-slug/' /&gt;</code></p>
<p>These canonical links help the search engines better understand the structure and content of your site. By including the canoncial element in your pages, you are telling Google et al which pages are <em>the</em> actual, canonical pages for your site. There are several cases where this is extremely helpful, namely:</p>
<ul>
<li>Social media linking often involves shortlinks &ndash; specifying a canonical link helps ensure that all of the shortlinking is sorted out and that your actual page gets the credit</li>
<li>Shopping cart sites that feature lots of query-string <acronym title="Uniform Resource Locator">URL</acronym>s &ndash; when many links look practically identical, having a canonical link specified helps to sort things out</li>
<li>Guest posting and other duplicate content &ndash; when your content is featured (or scraped) in multiple places around the Web, it is nice to have a clear signal as to which case is canonical</li>
</ul>
<h4>You don&#8217;t need htaccess to make changes</h4>
<p>What if you want to change the <em>general</em> structure of your permalinks? How do you go about doing that without losing your page rank while creating a mess of 404 errors? In older versions of WordPress, this was a real concern. Many folks began with full-date permalinks and then later realized they wanted cleaner, shorter, &ldquo;dateless&rdquo; permalinks instead. To do this back in the day, some <a href="http://perishablepress.com/press/2008/02/06/permalink-evolution-customize-and-optimize-your-dated-wordpress-permalinks/" title="Permalink Evolution: Customize and Optimize Your Dated WordPress Permalinks">HTAccess trickery</a> was required to keep the old links from going nowhere. </p>
<p>Fortunately those days are long gone, as WordPress now automagically handles all the redirecting for you when making changes to the <strong>general structure</strong> of your permalinks (via the <strong>Settings &gt; Permalinks</strong> options in the WordPress Admin). All you need to do is change the setting to whatever structure you would like and WordPress takes care of the rest. Just remember to backup your database and htaccess file before making any changes.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/07/optimizing-wordpress-permalinks/">Permalink</a> | <a href="http://digwp.com/2010/07/optimizing-wordpress-permalinks/#comments">38 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/07/optimizing-wordpress-permalinks/&title=Optimizing WordPress Permalinks">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/optimization/" rel="tag">optimization</a>, <a href="http://digwp.com/tag/permalink/" rel="tag">permalink</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/07/optimizing-wordpress-permalinks/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Redirect Dead-End Category, Search and Tag URLs</title>
		<link>http://digwp.com/2009/06/redirect-category-search-and-tag-urls/</link>
		<comments>http://digwp.com/2009/06/redirect-category-search-and-tag-urls/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 23:15:58 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[HTAccess]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[permalink]]></category>
		<category><![CDATA[redirects]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://modernwordpress.com/?p=40</guid>
		<description><![CDATA[Beginning with version 2.5, WordPress automatically handles many types of canonical redirects. A good example of this may be seen by typing your blog address into your browser both with and without the www prefix. If you are using WordPress 2.5 or better, one of these versions of your blog URL will be immediately redirected [...]]]></description>
			<content:encoded><![CDATA[<p>Beginning with version 2.5, WordPress automatically handles many types of canonical redirects. A good example of this may be seen by typing your blog address into your browser both with and without the <code>www</code> prefix. If you are using WordPress 2.5 or better, one of these versions of your blog URL will be immediately redirected to the other. The same type of automatic redirect may be seen for several other non-canonical URL variations, and is handled via PHP deep in the WordPress core.</p>
<p>As good as WordPress happens to be at catching and redirecting non-canonical requests, there are other types of problem URLs that need to be fixed. Specifically, for permalink-enabled WordPress sites, the following three URLs result in dead-end, 404 (Page Not Found) errors:</p>
<ul>
<li><code>http://your-domain.tld/blog/tag/</code></li>
<li><code>http://your-domain.tld/blog/search/</code></li>
<li><code>http://your-domain.tld/blog/category/</code></li>
</ul>
<p><span id="more-40"></span></p>
<p>The pages referred to by these URLs simply do not exist by default. Although these pages may not be requested by the average visitor, they are frequently visited by search engines such as Google. Whenever Google (or a curious visitor) attempts to load these pages, it encounters a dreaded 404 error. This is not good for your visitors and statistics, and it certainly isn&#8217;t helping your site&#8217;s search engine position and page rank. Fortunately, an easy fix is available for those on Apache servers with access to either their <code>httpd.conf</code> or root <code>HTAccess</code> file.</p>
<p>If your site is located in the root directory of your domain, place this code into your root HTAccess file:</p>
<pre><code>RedirectMatch 301 ^/tag/$      http://your-domain.com/
RedirectMatch 301 ^/search/$   http://your-domain.com/
RedirectMatch 301 ^/category/$ http://your-domain.com/</code></pre>
<p>Likewise, if your site is located in a subdirectory called &#8220;blog&#8221;, use this code instead, and place it into your site&#8217;s root HTAccess file:</p>
<pre><code>RedirectMatch 301 ^/blog/tag/$      http://your-domain.com/
RedirectMatch 301 ^/blog/search/$   http://your-domain.com/
RedirectMatch 301 ^/blog/category/$ http://your-domain.com/</code></pre>
<p>Almost done! If you are using the first block of code (WordPress installed in site root), edit each of the three instances of &#8220;<code>http://your-domain.com/</code>&#8221; to reflect the location to which you would like to redirect the dead-end URLs. For example, you may want to redirect all three URLs to your home page to extract any leftover rank juice. Another option would be to redirect each URL to a similar page on your site. Anything is possible here; proceed according to your own strategy.</p>
<p>If you are using the second block of code, in addition to editing each instance of &#8220;<code>http://your-domain.com/</code>&#8220;, you will also need to edit each instance of &#8220;<code>/blog/</code>&#8221; to match that of your actual subdirectory.</p>
<p>After editing the code and uploading to your site, you should now enjoy three less dead-end, 404 errors to worry about, while enjoying the SEO benefits of a cleaner, tighter WordPress-powered blog.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/06/redirect-category-search-and-tag-urls/">Permalink</a> | <a href="http://digwp.com/2009/06/redirect-category-search-and-tag-urls/#comments">12 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/06/redirect-category-search-and-tag-urls/&title=Redirect Dead-End Category, Search and Tag URLs">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/404/" rel="tag">404</a>, <a href="http://digwp.com/tag/permalink/" rel="tag">permalink</a>, <a href="http://digwp.com/tag/redirects/" rel="tag">redirects</a>, <a href="http://digwp.com/tag/search/" rel="tag">search</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/06/redirect-category-search-and-tag-urls/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Unique Body ID&#8217;s for your Pages</title>
		<link>http://digwp.com/2009/05/unique-body-ids-for-your-pages/</link>
		<comments>http://digwp.com/2009/05/unique-body-ids-for-your-pages/#comments</comments>
		<pubDate>Sat, 30 May 2009 16:46:51 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[permalink]]></category>

		<guid isPermaLink="false">http://modernwordpress.com/?p=18</guid>
		<description><![CDATA[There are many reasons you might want to get a unique ID for your tag. Let&#8217;s say you want your header elements to be a different color on your About page, you could style: h3 { color: blue; } body#about h3 { color: red; } But how do you get that ID on the About [...]]]></description>
			<content:encoded><![CDATA[<p>There are many reasons you might want to get a unique ID for your <tt><body></tt> tag. Let&#8217;s say you want your header elements to be a different color on your About page, you could style:</p>
<pre><code>h3 { color: blue; }
body#about h3 { color: red; }</code></pre>
<p>But how do you get that ID on the About page, but not on any other page? If you have your permalinks set up to show the page name, like <code>http://yoursite.com/about/</code>, you can use PHP to extract the &#8220;about&#8221; part of that URL.</p>
<p>Here is the magic:</p>
<pre><code>&lt;?php
	$url = explode('/',$_SERVER['REQUEST_URI']);
	$dir = $url[1] ? $url[1] : 'home';
?&gt;

&lt;body id="&lt;?php echo $dir ?&gt;"&gt;</code></pre>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/05/unique-body-ids-for-your-pages/">Permalink</a> | <a href="http://digwp.com/2009/05/unique-body-ids-for-your-pages/#comments">5 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/05/unique-body-ids-for-your-pages/&title=Unique Body ID&#8217;s for your Pages">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/body/" rel="tag">body</a>, <a href="http://digwp.com/tag/css/" rel="tag">CSS</a>, <a href="http://digwp.com/tag/header/" rel="tag">header</a>, <a href="http://digwp.com/tag/permalink/" rel="tag">permalink</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/05/unique-body-ids-for-your-pages/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

