<?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>MaisonBisson.com &#187; permalinks</title>
	<atom:link href="http://maisonbisson.com/blog/post/tag/permalinks/feed/" rel="self" type="application/rss+xml" />
	<link>http://maisonbisson.com</link>
	<description>A bunch of stuff I would have emailed you about.</description>
	<lastBuildDate>Sat, 14 Nov 2009 20:14:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Many Eyes, Bugs Being Shallow, All That</title>
		<link>http://maisonbisson.com/blog/post/12134/many-eyes-bugs-being-shallow-all-that/</link>
		<comments>http://maisonbisson.com/blog/post/12134/many-eyes-bugs-being-shallow-all-that/#comments</comments>
		<pubDate>Tue, 20 May 2008 08:45:34 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[bugfix]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[register_taxonomy()]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/?p=12134</guid>
		<description><![CDATA[
WordPress 2.5.1 added a really powerful feature to register_taxonomy(): automatic registration of permalinks and query vars to match the taxonomy. Well, theoretically it added that feature. It wasn&#8217;t working in practice. After some searching yesterday and today, I finally found the bug and worked up a fix. I made a diff and set off to [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12134"><!-- &nbsp; --></abbr>
<p>WordPress 2.5.1 added a really powerful feature to <code>register_taxonomy()</code>: automatic registration of permalinks and query vars to match the taxonomy. Well, theoretically it added that feature. It wasn&#8217;t working in practice. After some searching yesterday and today, I finally found the bug and worked up a fix. I made a diff and set off to open a ticket in Trac.</p>
<p>On the one hand I&#8217;m glad I searched first, because it turns out that a ticket on the very same issue was <a href="http://trac.wordpress.org/ticket/6981">opened on May 16th</a> and it already <a href="http://trac.wordpress.org/changeset/7940">has a fix</a>. On the other hand, it&#8217;s kind of a kicker to have lost my chance at reporting the bug and submitting a fix by only a few days.</p>
<p>The fix is committed for WordPress 2.6, but I&#8217;ve done a workaround for 2.5.1 (workarounds are easier to manage than core code changes). I&#8217;d say I wish I searched Trac first, but I wouldn&#8217;t have known what to search for if I didn&#8217;t figure out how to fix the bug first. And I guess I really can&#8217;t complain about <a href="http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/ar01s04.html">a community that quickly finds and fixes bugs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12134/many-eyes-bugs-being-shallow-all-that/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress + Invalid URLs = Extra Database Queries</title>
		<link>http://maisonbisson.com/blog/post/12035/wordpress-invalid-urls-extra-database-queries/</link>
		<comments>http://maisonbisson.com/blog/post/12035/wordpress-invalid-urls-extra-database-queries/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 13:38:13 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[behavior]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/post/12035/wordpress-invalid-urls-extra-database-queries</guid>
		<description><![CDATA[
After reporting weirdness last week I finally sat down with a completely clean and virgin install of WordPress 2.3.2 and traced what happens when you make a permalink request for a non-existent URL.
Here are two sets of URLs to use as examples and context:

These are valid URLs:

http://site.org/archives/101
http://site.org/page-name


These are _not_ valid URLs:

http://site.org/archivezorz/101
http://site.org/favicon.ico



Valid URLs get parsed, the [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12035"><!-- &nbsp; --></abbr>
<p>After <a href="http://comox.textdrive.com/pipermail/wp-hackers/2008-January/017144.html">reporting weirdness last week</a> I finally sat down with a completely clean and virgin install of WordPress 2.3.2 and traced what happens when you make a permalink request for a non-existent URL.</p>
<p>Here are two sets of URLs to use as examples and context:</p>
<ul>
<li>These are valid URLs:
<ul>
<li>http://site.org/archives/101</li>
<li>http://site.org/page-name</li>
</ul>
</li>
<li>These are _not_ valid URLs:
<ul>
<li>http://site.org/archivezorz/101</li>
<li>http://site.org/favicon.ico</li>
</ul>
</li>
</ul>
<p>Valid URLs get parsed, the expected MySQL queries get executed, and the results are processed and returned to the browser. Normal. The problem is that invalid URLs that get sent through WordPress still result in a query like the following being executed on the database. What?</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #990099; font-weight: bold;">SQL_CALC_FOUND_ROWS</span>  test_posts.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> test_posts  <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008080;">1</span><span style="color: #CC0099;">=</span><span style="color: #008080;">1</span>  <span style="color: #CC0099; font-weight: bold;">AND</span> post_type <span style="color: #CC0099;">=</span> <span style="color: #008000;">'post'</span> <span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#40;</span>post_status <span style="color: #CC0099;">=</span> <span style="color: #008000;">'pub
lish'</span> <span style="color: #CC0099; font-weight: bold;">OR</span> post_status <span style="color: #CC0099;">=</span> <span style="color: #008000;">'private'</span><span style="color: #FF00FF;">&#41;</span>  <span style="color: #990099; font-weight: bold;">ORDER BY</span> post_date <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">0</span><span style="color: #000033;">,</span> <span style="color: #008080;">10</span></pre></div></div>

<p>That is, even after a URL is sent through <code>WP->parse_request()</code> and found to be invalid/404, WordPress marches on to <code>WP->query_posts()</code> and hits the database with a generic request for the X most recent posts. And because this is executed for every 404, it actually results in a lot of database activity.</p>
<p>In most cases MySQL has cached the result, and so it poses a minimal load on the server. And even if the cache is stale, for most sites it&#8217;s not a particularly resource intensive query.</p>
<p>But, if you&#8217;ve got <a href="http://library.plymouth.edu/browse/?subj=20th+century">350,000 rows in the posts table</a>, it&#8217;s incredibly resource intensive to order all those posts on the <code>post_date</code> (<code>datetime</code>) column. I&#8217;ve seen hundreds of them pile up and take <em>forever</em> to complete after writes to the table. It&#8217;s sufferable if write activity on the posts table is very low, but that&#8217;s not something I want to hope for.</p>
<p>So <a href="http://comox.textdrive.com/pipermail/wp-hackers/2008-January/017264.html">my question to the wp-hackers community</a> is: Do we actually want to execute that query for every 404 under normal circumstances? If not, is the following (or something like it) the stupidest solution?</p>
<p>In <a href="http://svn.automattic.com/wordpress/tags/2.3.2/wp-includes/classes.php">wp-includes/classes.php</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">function</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_the_query</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">build_query_string</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// return if the request URI is a 404</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">did_permalink</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'404'</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wp_the_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query_vars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above works, but there&#8217;s probably a better way to write it.</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12035/wordpress-invalid-urls-extra-database-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress, Permalinks, Mod_Rewrite, and Avoiding 404s</title>
		<link>http://maisonbisson.com/blog/post/11617/wordpress-permalinks-mod_rewrite-and-avoiding-404s/</link>
		<comments>http://maisonbisson.com/blog/post/11617/wordpress-permalinks-mod_rewrite-and-avoiding-404s/#comments</comments>
		<pubDate>Thu, 19 Apr 2007 16:31:59 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[apache rewrite]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rewrite rules]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/post/11617/#wordpress-permalinks-mod_rewrite-and-avoiding-404s</guid>
		<description><![CDATA[
I made a mistake in changing my WordPress permalinks, but by the time I&#8217;d discovered it my blog had already been indexed. Fixing the permalinks meant breaking those indexed URLs, leading to a bad user experience, but leaving them as is wasn&#8217;t really an option.
Last night, after getting 404&#8242;d while using Google to search my [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-11617"><!-- &nbsp; --></abbr>
<p>I made a mistake in changing my <a href="http://codex.wordpress.org/Using_Permalinks">WordPress permalinks</a>, but by the time I&#8217;d discovered it my blog had already been indexed. Fixing the permalinks meant breaking those indexed URLs, leading to a bad user experience, but leaving them as is wasn&#8217;t really an option.</p>
<p>Last night, after getting 404&#8242;d while using Google to search my own blog, I realized I had to do something.</p>
<p>First I looked at <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html" title="Apache module mod_rewrite">Apache mod_rewrite</a> and the <a href="http://httpd.apache.org/docs/1.3/misc/rewriteguide.html" title="Apache 1.3 URL Rewriting Guide">URL rewriting guide</a> (as well as this <a href="http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf" title="http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf">cheat sheet</a> from <a href="http://www.ilovejackdaniels.com/cheat-sheets/" title="http://www.ilovejackdaniels.com/cheat-sheets/">ilovejackdaniels</a>), Then, frustrated, I found some items in the WordPress Codex, including this one about <a href="http://wordpress.org/support/topic/111914">conflicts between .htaccess files/rules</a> and this about <a href="http://wordpress.org/support/topic/89515">problems with subdirectories inside the WordPress root</a>. </p>
<p>The suggestions in both boil down to creating a specific error document:</p>
<blockquote><p>Create a file on your website. Call it onerror.html. It can be empty or have just &lt;html&gt;&lt;/html&gt; in it for all that it matters.</p>
<p>In Wordpress&#8217;s .htaccess file, add this to the top of the file:<br />
ErrorDocument 401 /path/to/onerror.html<br />
ErrorDocument 403 /path/to/onerror.html</p></blockquote>
<p><a href="http://wordpress.org/support/topic/89515?replies=6#post-454369">The explanation</a>, though even the poster doesn&#8217;t claim to know that it&#8217;s the correct explanation, is that the rules are additive, and WordPress is greedy with trying to get requests directed to its own URL parsing routines. The ErrorDocument is supposed to keep more of the processing in mod_rewrite.</p>
<p>But after all that, and only limited success achieving what I wanted, I realized that what I really wanted was not to parse requests before WordPress had a chance at them (as would happen with rewrite rules), but to handle requests that WordPress&#8217; internal rules couldn&#8217;t match.</p>
<p>What I ended up doing is writing a tiny plugin that hooked into the <a href="http://wphooks.flatearth.org/hooks/template_redirect/" title="WordPress Hooks » Blog Archive » template_redirect">template_redirect</a> hook. The short of it is that if WordPress thinks it&#8217;s 404&#8242;d, and I can divine some meaning from the requested URL, then I redirect to browser (including a <code>HTTP/1.1 301 Moved Permanently</code> statement). Voila, it works.</p>
<p><tags>wordpress, rewrite, mod_rewrite, rewrite rules, apache rewrite, permalinks, redirect, 404</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/11617/wordpress-permalinks-mod_rewrite-and-avoiding-404s/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>