<?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; HTAccess</title>
	<atom:link href="http://digwp.com/category/htaccess/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>6 .htaccess Tricks for Better WordPress SEO &amp; Security</title>
		<link>http://digwp.com/2011/03/htaccess-wordpress-seo-security/</link>
		<comments>http://digwp.com/2011/03/htaccess-wordpress-seo-security/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 23:59:08 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[HTAccess]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3712</guid>
		<description><![CDATA[Here are six htacccess tricks that will help improve the security and SEO quality of your WordPress-powered site. We do this using .htaccess to establish canonical URLs for key peripheral files, such as your robots.txt, favicon.ico, and sitemap.xml files. Canonicalization keeps legitimate bots on track, eliminates malicious behavior, and ensures a better user-experience for everyone. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are <strong>six htacccess tricks</strong> that will help improve the security and <abbr title="Search Engine Optimization">SEO</abbr> quality of your WordPress-powered site. We do this using .htaccess to establish <strong>canonical <abbr title="Uniform Resource Locator">URL</abbr>s</strong> for key peripheral files, such as your <code>robots.txt</code>, <code>favicon.ico</code>, and <code>sitemap.xml</code> files. Canonicalization keeps legitimate bots on track, eliminates malicious behavior, and ensures a better user-experience for everyone. On the menu:</p>
<p><span id="more-3712"></span></p>
<ol>
<li><a href="#canonical-robots">Canonical robots.txt</a></li>
<li><a href="#canonical-favicons">Canonical Favicons</a></li>
<li><a href="#canonical-sitemaps">Canonical Sitemaps</a></li>
<li><a href="#canonical-urls">Canonical Category, Tag &amp; Search URLs</a></li>
<li><a href="#canonical-feeds">Canonical Feeds</a></li>
<li><a href="#canonical-login">Simpler Login URL</a></li>
</ol>
<h3>Before making changes..</h3>
<p>The .htaccess code in this post is designed to work when placed in the web-accessible root .htaccess file of your domain. Before making any changes to this file, make a good backup and keep it on hand just in case. Working with .htaccess is nothing to be afraid of, but it&#8217;s <em>critical</em> to not make any mistakes in syntax, spelling, or anything that&#8217;s not a comment (<code>#</code>). If you forget a dot working with <abbr title="Cascading Style Sheets">CSS</abbr>, your design might look messed up. If you forget a dot working with .htaccess your server will return a <strong>500 &ndash; Internal Server Error</strong>. If this happens, <em>don&#8217;t panic</em>, just upload your backup and everything will be fine.</p>
<h3 id="canonical-robots">1. Canonical robots.txt</h3>
<p>Help bots and visitors find your <code>robots.txt</code> file no matter what. Given that the <code>robots.txt</code> file should always be located in the root directory, you would <em>think</em> that this wouldn&#8217;t be an issue. Unfortunately, bad bots and malicious scripts like to scan for <code>robots.txt</code> files <a href="http://perishablepress.com/malicious-server-scans/" title="What a Malicious Server Scan Looks Like">everywhere</a>. Fortunately, this .htaccess snippet eliminates the nonsense by directing any request for &#8220;robots.txt&#8221; to the actual file in your root directory. If you&#8217;re sick of seeing endless requests for nonexistent robots files, this code&#8217;s for you:</p>
<pre><code># CANONICAL ROBOTS.TXT
&lt;IfModule mod_rewrite.c&gt;
 RewriteBase /
 RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
 RewriteCond %{REQUEST_URI} robots\.txt [NC]
 RewriteRule .* http://example.com/robots.txt [R=301,L]
&lt;/IfModule&gt;</code></pre>
<p>To use this code, replace <code>example.com</code> with your own domain and include in your web-accessible root directory. These directives collectively redirect all requests for any &#8220;robots.txt&#8221; file, with the exception of the actual, root robots.txt file. If you need to whitelist a similarly named file, just include the following line beneath the first <code>RewriteCond</code>, replacing the path and file name with your own:</p>
<p><code>RewriteCond %{REQUEST_URI} !/wordpress/robots.txt$ [NC]</code></p>
<p><strong>Alternate Method:</strong> Instead of using Apache&#8217;s <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html" title="Apache Module mod_rewrite">rewrite module</a>, we can do the <a href="http://perishablepress.com/press/2009/05/11/htaccess-spring-cleaning/" title="HTAccess Spring Cleaning 2009">same thing with less code</a> using <a href="http://httpd.apache.org/docs/current/mod/mod_alias.html" title="Apache Module mod_alias">mod_alias</a>:</p>
<p><code>RedirectMatch 301 ^/(.*)/robots\.txt http://example.com/robots.txt</code></p>
<p>Either method is effective, but <code>mod_alias</code> is optimal for typical sites with only one robots.txt file. If you have multiple robots.txt files, the <code>mod_rewrite</code> method will enable complete granular control from the root .htaccess file.</p>
<h3 id="canonical-favicons">2. Canonical Favicons</h3>
<p>Avatars, gravatars, and favicons are a big hit with malicious scanners. Evil scripts like to traverse your directory structure with requests for commonly used images such as the ubiquitous <code>favicon.ico</code>. So just as with <code>robots.txt</code>, we can <a href="http://perishablepress.com/press/2008/08/11/block-favicon-url-404-requests/" title="Stop the Madness: Redirect those Ridiculous Favicon 404 Requests">stop the madness</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">redirect any request for &#8220;favicon.ico&#8221; to the actual file</a> in your root directory.</p>
<pre><code># CANONICAL FAVICONS
&lt;IfModule mod_rewrite.c&gt;
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_URI} !^/favicon.ico$ [NC]
 RewriteCond %{REQUEST_URI} /favicon(s)?\.?(gif|ico|jpe?g?|png)?$ [NC]
 RewriteRule (.*) http://example.com/favicon.ico [R=301,L]
&lt;/IfModule&gt;</code></pre>
<p>To use this code, replace <code>example.com</code> with your own domain and include in your web-accessible root directory. These directives collectively redirect all requests for any &#8220;<code>favicon</code>&#8221; or &#8220;<code>favicons</code>&#8221; with a <code>.png</code>, <code>.gif</code>, <code>.ico</code>, or <code>.jpg</code> extension. To prevent an infinite request loop, the code includes an exception for the actual, root &#8220;<code>favicon.ico</code>&#8221; file. If you need to whitelist a similarly named file, just include the following line beneath the first <code>RewriteCond</code>, replacing the path and file name with your own:</p>
<p><code>RewriteCond %{REQUEST_URI} !/images/favicons.png$ [NC]</code></p>
<h3 id="canonical-sitemaps">3. Canonical Sitemaps</h3>
<p>Just as idiotic bots can&#8217;t seem to find your robots and favicon files, so too are they clueless when it comes to finding your sitemap, even when declared in the robots.txt file. Nefarious bots will ignore your robots suggestions and hammer your site with ill-requests for nonexistent sitemaps. This malicious behavior chews up system resources and wastes bandwidth. To eliminate the waste while helping stupid bots find your sitemap, slip this into your root .htaccess:</p>
<pre><code># CANONICAL SITEMAPS
&lt;IfModule mod_alias.c&gt;
 RedirectMatch 301 /sitemap\.xml$ http://example.com/sitemap.xml
 RedirectMatch 301 /sitemap\.xml\.gz$ http://example.com/sitemap.xml.gz
&lt;/IfModule&gt;</code></pre>
<p>To use this code, edit each rule with your own domains and file paths. The first rule redirects all requests for your regular, uncompressed sitemap, and the second rule redirects all requests for your compressed (gzipped) sitemap. These rules are independent of each other, so feel free to remove either to suit your needs.</p>
<h3 id="canonical-urls">4. Canonical Category, Tag, and Search URLs</h3>
<p>Out of the box, WordPress returns a <strong>404 &ndash; Not Found</strong> for the following URLs:</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>These are commonly requested URLs that may be leaking valuable page rank. As <a href="http://digwp.com/2009/06/redirect-category-search-and-tag-urls/" title="Redirect Dead-End Category, Search and Tag URLs">explained previously</a>, you can use the following slice of .htaccess to redirect these URLs to your home page (or anywhere else):</p>
<pre><code># CANONICAL URLs
&lt;IfModule mod_alias.c&gt;
 RedirectMatch 301 ^/tag/$      http://example.com/
 RedirectMatch 301 ^/search/$   http://example.com/
 RedirectMatch 301 ^/category/$ http://example.com/
&lt;/IfModule&gt;</code></pre>
<p>To use, place the previous code into your root .htaccess file and replace each <code>example.com</code> with the desired redirect location. Alternately, if WordPress is <a href="http://digwp.com/2009/07/move-your-wordpress-files-out-of-the-root-directory/" title="Move Your WordPress Files Out of the Root Directory">installed in a subdirectory</a>, use this code instead:</p>
<pre><code># CANONICAL URLs
&lt;IfModule mod_alias.c&gt;
 RedirectMatch 301 ^/blog/tag/$      http://example.com/
 RedirectMatch 301 ^/blog/search/$   http://example.com/
 RedirectMatch 301 ^/blog/category/$ http://example.com/
&lt;/IfModule&gt;</code></pre>
<p>Again, edit the examples with your actual URLs. A good place to redirect any juice or traffic from these three URLs is the home page. Hopefully future versions of WordPress will handle these redirects internally, but until then, this bit of .htaccess is a simple and effective solution.</p>
<h3 id="canonical-feeds">5. Canonical Feeds</h3>
<p>WordPress generates many <a href="http://perishablepress.com/press/2008/03/09/what-is-my-wordpress-feed-url/" title="http://perishablepress.com/press/2008/03/09/what-is-my-wordpress-feed-url/">different feeds for your site</a>. The default feed configuration works great, but it&#8217;s worth including in this post a couple of useful .htaccess tricks:</p>
<ul>
<li>Set up canonical feed types (e.g., deliver only RSS2 feeds and redirect other formats)</li>
<li>Setup FeedBurner feeds and redirect associated feed requests</li>
</ul>
<p>Each of these techniques are easily achieved with a little .htaccess. Better grab a beverage..</p>
<h4>Set up canonical feeds</h4>
<p>WordPress provides feeds in four different formats: Atom, RDF, RSS, and RSS2. This variety was useful in the past to accommodate different apps and devices, but these days I think it&#8217;s safe to say that most readers and devices can handle any format you throw at it. So instead of having 4x the feeds, you can consolidate your feeds into a single format:</p>
<pre><code># CANONICAL FEEDS
&lt;IfModule mod_alias.c&gt;
 RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://example.com/feed/
 RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://example.com/comments/feed/
&lt;/IfModule&gt;</code></pre>
<p>This code will redirect requests for alternate feed formats to your canonical choice for both main-content feed and all-comments feed. To use this code, replace both of the target URLs with your own and place in the web-accessible root directory.</p>
<h4>Redirect feeds to FeedBurner</h4>
<p>Redirecting feeds to FeedBurner is another useful .htaccess snippet to have in your tool belt. Here are two snippets to do the job &ndash; one for main-content and another for all-comments feeds:</p>
<pre><code># REDIRECT to FEEDBURNER
&lt;IfModule mod_rewrite.c&gt;
 RewriteCond %{REQUEST_URI} ^/feed/ [NC]
 RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
 RewriteRule .* http://feeds.feedburner.com/mainContentFeed [L,R=302]

 RewriteCond %{REQUEST_URI} ^/comments/feed/ [NC]
 RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
 RewriteRule .* http://feeds.feedburner.com/allCommentsFeed [L,R=302]
&lt;/IfModule&gt;</code></pre>
<p>The first block redirects all requests for your main-content feed, and the second block handles your all-comments feed. So to use, just replace the <code>mainContentFeed</code> and <code>allCommentsFeed</code> with the URLs of your associated FeedBurner feeds. You may also redirect special category feeds by replicating the pattern with another block of code:</p>
<pre><code> RewriteCond %{REQUEST_URI} ^/category/wordpress/feed/ [NC]
 RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
 RewriteRule .* http://feeds.feedburner.com/specialCategoryFeed [L,R=302]</code></pre>
<p>As before, just replace the URL of your FeedBurner feed in the <code>RewriteRule</code> and test accordingly.</p>
<h3 id="canonical-login">6. Simpler Login URL</h3>
<p>Lastly, a cool .htaccess trick for a <a href="http://digwp.com/2011/01/simpler-login-url/" title="Simpler Login URL">better user-login</a> experience. A single line of code placed in your root .htaccess file is all it takes:</p>
<pre><code>RewriteRule ^login$ http://example.com/wp-login.php [NC,L]</code></pre>
<p>Edit the <code>example.com</code> with the domain/path of your WordPress installation. Now instead of typing &ldquo;<code>wp-login.php</code>&rdquo;, we just type &ldquo;<code>login</code>&rdquo; and whoop, there it is.</p>
<p>You could also use <code>RedirectMatch</code> to enable a login URL switch:</p>
<p><code>RedirectMatch 301 \@admin http://example.com/wp-admin</code></p>
<p>The <code>@</code> prevents the rule from bothering anything else, and <code>RedirectMatch</code> picks up on the switch from anywhere in the site, so regardless of what page you’re on, you just append &ldquo;<code>@admin</code>&rdquo; to the URL and you’re there. I use this trick at <a href="http://perishable.biz" title="Cool graphics &#038; stuff">http://perishable.biz</a> if you want to see it work. Check the comments of <a href="http://digwp.com/2011/01/simpler-login-url/" title="Simpler Login URL">Chris&#8217; original post</a> for good discussion and some more great ideas.</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/03/htaccess-wordpress-seo-security/">Permalink</a> | <a href="http://digwp.com/2011/03/htaccess-wordpress-seo-security/#comments">20 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/03/htaccess-wordpress-seo-security/&title=6 .htaccess Tricks for Better WordPress SEO &amp; Security">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/htaccess-2/" rel="tag">htaccess</a>, <a href="http://digwp.com/tag/performance/" rel="tag">performance</a>, <a href="http://digwp.com/tag/seo/" rel="tag">SEO</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/03/htaccess-wordpress-seo-security/feed/</wfw:commentRss>
		<slash:comments>20</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>3 Ways to Monitor PHP Errors</title>
		<link>http://digwp.com/2009/07/monitor-php-errors-wordpress/</link>
		<comments>http://digwp.com/2009/07/monitor-php-errors-wordpress/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 05:51:22 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[HTAccess]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[maintenance]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=376</guid>
		<description><![CDATA[Close monitoring of your site&#8217;s PHP errors is crucial to operating a healthy, secure, and well-performing website. When left undetected, PHP errors can reduce performance, waste bandwidth, and leave your site vulnerable to malicious attack. PHP errors usually occur unpredictably and spontaneously, and may be triggered by even the slightest changes to your server configuration, [...]]]></description>
			<content:encoded><![CDATA[<p>Close monitoring of your site&rsquo;s <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors is crucial to operating a healthy, secure, and well-performing website. When left undetected, <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors can reduce performance, waste bandwidth, and leave your site vulnerable to malicious attack. <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors usually occur unpredictably and spontaneously, and may be triggered by even the slightest changes to your server configuration, database setup, or WordPress files. Even if your site appears to working properly on the surface, it may in fact be suffering from undetected <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors that should be fixed as soon as possible. </p>
<p>Monitoring <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors is something that all responsible WordPress administrators should be doing. In this <acronym title="Digging into WordPress">DiW</acronym> article, we&rsquo;ll show you three easy ways to monitor <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors for WordPress. The first method is exclusive to WordPress, and the second two methods work great for <em>any</em> website.</p>
<p><span id="more-376"></span></p>
<h3>Method 1: Error Logging via the WordPress configuration file</h3>
<p>Perhaps the <em>easiest</em> way to implement <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error-logging for your WordPress-powered site is to add a few simple lines of code to your <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks"><code>wp-config.php</code> file</a>. The WordPress <code>wp-config.php</code> file may be used to specify various <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> initiation settings to modify the functionality of your <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> installation. In this method, we will take advantage of this feature by implementing basic error monitoring for your site. Here&rsquo;s how to do it:</p>
<p><strong>Step 1: Create a log file</strong></p>
<p>Create an empty file called &ldquo;<code>php-errors.log</code>&rdquo;. This file will serve as your site&rsquo;s <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error log. Your server will need write access to this file, so make sure to set the appropriate permissions. This file may be placed in any directory, but placing it <em>above</em> the web-accessible root directory of your site is advisable for security reasons. Once this file is created, writable, and in place, take note of its absolute directory path and continue to the final step.</p>
<p><strong>Step 2: Add the magic code</strong></p>
<p>Next, open your site&rsquo;s <code>wp-config.php</code> file (located in the root WordPress directory) and place the following code immediately <em>above</em> the line that says, &ldquo;<code>That's all, stop editing! Happy blogging.</code>&rdquo;:</p>
<pre><code>// log php errors
@ini_set('log_errors','On'); // enable or disable php error logging (use 'On' or 'Off')
@ini_set('display_errors','Off'); // enable or disable public display of errors (use 'On' or 'Off')
@ini_set('error_log','/home/path/logs/php-errors.log'); // path to server-writable log file</code></pre>
<p>Once in place, edit the third line with the absolute directory path to the <code>php-errors.log</code> file created in the first step. Upload to your server and call it done. All <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors will now be logged to your <code>php-errors.log</code> file, thereby enabling you to monitor and resolve errors as quickly as possible.</p>
<p>The other two directives in this tasty little snippet enable you to log and display <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors at your will. The current configuration is ideal for production sites, but you may want to <em>enable</em> <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error display for development purposes. See the code comments for more information on changing these settings.</p>
<p><strong>Cool tips</strong></p>
<p>A couple of notes regarding this method.. First, if you place the following definition to your <code>wp-config.php</code> file, all WordPress debug errors will also be written to your <code>php-errors.log</code> file:</p>
<p><code>define('WP_DEBUG', true); // enable debugging mode</code></p>
<p>Also note that the code used for this example demonstrates a very basic implementation. You may add any number of additional <code>@ini_set()</code> directives to enhance and customize your error-logging system as needed.</p>
<h3>Method 2: Error Logging via the PHP initiation file</h3>
<p>If you have access to your site&rsquo;s <code>php.ini</code> file, or if you are able to implement &ldquo;per-directory&rdquo; initiation files, this method will enable you to monitor <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors for <em>any</em> website, not just those powered by WordPress. The process is very similar to the previous method, and requires the following two steps:</p>
<p><strong>Step 1: Create a log file</strong></p>
<p>Create an empty file called &ldquo;<code>php-errors.log</code>&rdquo;. This file will serve as your site&rsquo;s <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error log. Your server will need write access to this file, so make sure to set the appropriate permissions. This file may be placed in any directory, but placing it <em>above</em> the web-accessible root directory of your site is advisable for security reasons. Once this file is created, writable, and in place, take note of its absolute directory path and continue to the final step.</p>
<p><strong>Step 2: Add the magic code</strong></p>
<p>Next, open your site&rsquo;s <code>php.ini</code> file and add the following code:</p>
<pre><code>;;; log php errors
display_startup_errors = false
display_errors = false
html_errors = false
log_errors = true
track_errors = true
error_log = /home/path/logs/php-errors.log
error_reporting = E_ALL | E_STRICT
log_errors_max_len = 0</code></pre>
<p>As before, this code is configured for optimal error-handling for production servers. The only thing that you need to edit is the absolute directory path for your log file. During site development, you may want to change some of the variables to enable error display, startup errors, repeat errors, and so forth. For more information on these directives, and for a more in-depth guide to logging errors with <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>, check out my article at Perishable Press, <a href="http://perishablepress.com/press/2008/01/30/advanced-php-error-handling-via-php/" title="Advanced PHP Error Handling via PHP">Advanced PHP Error Handling via PHP</a>.</p>
<h3>Method 3: Error Logging via the HTAccess file</h3>
<p>Last but not least, let&rsquo;s look at <a href="http://perishablepress.com/press/2007/12/17/how-to-enable-php-error-logging-via-htaccess/" title="How to Enable PHP Error Logging via htaccess">how to enable <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error-logging via HTAccess</a>. This method works great if <acronym title="Hypertext Access">HTAccess</acronym> files are enabled on your site, and will enable you to log <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors on <em>any</em> site, not just those powered by WordPress. The process is very similar to the previous method, and requires the following two steps:</p>
<p><strong>Step 1: Create a log file</strong></p>
<p>Create an empty file called &ldquo;<code>php-errors.log</code>&rdquo;. This file will serve as your site&rsquo;s <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error log. Your server will need write access to this file, so make sure to set the appropriate permissions. This file may be placed in any directory, but placing it <em>above</em> the web-accessible root directory of your site is advisable for security reasons. Once this file is created, writable, and in place, take note of its absolute directory path and continue to the final step.</p>
<p><strong>Step 2: Add the magic code</strong></p>
<p>Next, open your site&rsquo;s root <code>.htaccess</code> file and add the following code:</p>
<pre><code># log php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag  log_errors on
php_value error_log /home/path/logs/php-errors.log</code></pre>
<p>As before, this code is configured for optimal error-handling for production servers. The only thing that you need to edit is the absolute directory path for your log file. During site development, you may want to change some of the variables to enable error display, startup errors, repeat errors, and so forth. For more information on these directives, and for a more in-depth guide to logging <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors via <acronym title="Hypertext Access">HTAccess</acronym>, check out my article at Perishable Press, <a href="http://perishablepress.com/press/2008/01/14/advanced-php-error-handling-via-htaccess/" title="Advanced PHP Error Handling via htaccess">Advanced PHP Error Handling via htaccess</a>.</p>
<h3>Troubleshooting Tips</h3>
<p>To determine the absolute path of your log file, upload a <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> with the following code to the same directory and open it in a browser:</p>
<p><code>&lt;h3&gt;&lt;?php echo $_SERVER['DOCUMENT_ROOT']; ?&gt;&lt;/h3&gt;</code></p>
<p>Depending on your server configuration, you may need to use method #1 or #2 if you are running PHP5. Certain dual-PHP setups and other configurations may require any <code>php_value</code> directives to be placed in a <code>php.ini</code> file instead of <code>htaccess</code>.</p>
<p>An easy way to test that your error-logging system is working is to trigger a few basic <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> errors. To do so, create a <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> file and add something that will trigger an error, for example:</p>
<p><code>&lt;?php echo "error" ?&gt;</code></p>
<p>Lastly, if you are triggering errors but nothing is being written to your log file, triple-check that the file is writable by the server. Depending on your particular server configuration, you may need to increase the permissions level of the file. If you have to run with a setting of &ldquo;<code>777</code>&rdquo; (full permissions), definitely make sure that the log file is placed above the web-accessible root directory of your site.</p>
<h3>Wrap it up then</h3>
<p>With one of these three <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> error-logging techniques, you have everything you need to implement easy, automatic error-logging for your website. Everything happens quietly behind the scenes, so remember to keep an eye on things by checking your log file periodically. Doing so will enable you to ensure a well-performing site and the best possible experience for your visitors.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/monitor-php-errors-wordpress/">Permalink</a> | <a href="http://digwp.com/2009/07/monitor-php-errors-wordpress/#comments">15 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/monitor-php-errors-wordpress/&title=3 Ways to Monitor PHP Errors">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/errors/" rel="tag">errors</a>, <a href="http://digwp.com/tag/maintenance/" rel="tag">maintenance</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/monitor-php-errors-wordpress/feed/</wfw:commentRss>
		<slash:comments>15</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>
	</channel>
</rss>

