<?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/"
xmlns:media="http://search.yahoo.com/mrss/"
><channel><title>YoastServerside - Archives - Yoast - Tweaking Websites</title> <atom:link href="http://yoast.com/tag/serverside/feed/" rel="self" type="application/rss+xml" /><link>http://yoast.com</link> <description>Tweaking Websites</description> <lastBuildDate>Thu, 02 Sep 2010 14:00:08 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=</generator> <image><title>Yoast</title> <url>http://cdn.yoast.com/wp-content/themes/yoast-v2/images/yoast-logo-rss.png</url><link>http://yoast.com</link> <width>144</width> <height>103</height> <description>Tweaking Websites</description> </image> <item><title>Move your WordPress blog to a new domain in 10 steps!</title><link>http://yoast.com/move-wordpress-blog-domain-10-steps/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=move-wordpress-blog-domain-10-steps</link> <comments>http://yoast.com/move-wordpress-blog-domain-10-steps/#comments</comments> <pubDate>Thu, 14 Feb 2008 21:45:30 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[SEO]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[Serverside]]></category> <category><![CDATA[WordPress Plugins]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/move-your-wordpress-blog-to-a-new-domain-in-10-steps/</guid> <description><![CDATA[<p>A friend recently asked me how to move his blog, which is on /blog/ on his domain, to a new domain on it's own. The steps are easy, but have to be taken in the right order to make sure you're not annoying your users and the search engines: Put up a robots.txt on the [...]</p><p><a
href="http://yoast.com/move-wordpress-blog-domain-10-steps/">Move your WordPress blog to a new domain in 10 steps!</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p>A friend recently asked me how to move his blog, which is on /blog/ on his domain, to a new domain on it's own. The steps are easy, but have to be taken in the right order to make sure you're not annoying your users and the search engines:</p><ol><li>Put up a <code>robots.txt</code> on the new domain with the following contents:<pre>User-agent: *
Disallow: /</pre></li><li>Copy the database and files to the new domain.</li><li>Edit <code>wp-config.php</code> to have the right database settings, and add the following lines, replacing sample.com with the right domain:<div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_SITEURL'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://www.example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_HOME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://www.example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></li><li>Now set up your blog install, with the same settings as on the old domain (if you have a caching plugin installed, delete your cache files).</li><li>Install the <a
href="http://wordpress.org/extend/plugins/search-and-replace/">Search and Replace plugin</a>, and do a search and replace for your old URL's and change them with your new URL's.</li><li>Once you're done, and you've checked everything works <strong>twice</strong>:</li><li>Remove the <code>robots.txt</code> file.</li><li>On your old blog, add the following line to your apache <code>.htaccess</code> or vhost-config:<pre>Redirect 301 /blog/ http://www.newdomain.com/</pre></li><li>Remove the old blog code and database.</li><li>Change your FeedBurner account, if you have one, to pick up the correct feed.</li></ol><p>That should be it. If you have any suggestions or spot things that I've missed, please note them in the comments!</p><p><a
href="http://yoast.com/move-wordpress-blog-domain-10-steps/">Move your WordPress blog to a new domain in 10 steps!</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/move-wordpress-blog-domain-10-steps/feed/</wfw:commentRss> <slash:comments>123</slash:comments> </item> <item><title>Playing with the X-Robots-Tag HTTP header</title><link>http://yoast.com/x-robots-tag-play/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=x-robots-tag-play</link> <comments>http://yoast.com/x-robots-tag-play/#comments</comments> <pubDate>Sun, 20 Jan 2008 20:41:57 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[SEO]]></category> <category><![CDATA[Microformats]]></category> <category><![CDATA[SEO tools]]></category> <category><![CDATA[Serverside]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/x-robots-tag-play/</guid> <description><![CDATA[<p>Ever since the announcement on the Google Blog and more recently Yahoo's announcement that they've enhanced their support for it, I've been meaning to play with the X-Robots-Tag header. This HTTP header allows you to do what you'd normally do in a robots meta tag, in an HTTP header, which has some pretty cool appliances. [...]</p><p><a
href="http://yoast.com/x-robots-tag-play/">Playing with the X-Robots-Tag HTTP header</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p>Ever since the <a
href="http://googleblog.blogspot.com/2007/07/robots-exclusion-protocol-now-with-even.html">announcement on the Google Blog</a> and more recently Yahoo's announcement that they've <a
href="http://www.seroundtable.com/archives/015636.html">enhanced their support for it</a>, I've been meaning to play with the X-Robots-Tag header. This HTTP header allows you to do what you'd normally do in a <a
href="http://yoast.com/wordpress/meta-robots-wordpress-plugin/robots-meta-tags/">robots meta tag</a>, in an HTTP header, which has some pretty cool appliances. I'll show you a few cool things you can do with this, but first some theory. If you don't feel like that, skip to the <a
href="http://yoast.com/x-robots-tag-play/#examples">example uses of the X-Robots-Tag</a>.</p><p>As Sebastian explained in <a
href="http://www.seomoz.org/blog/robots-exclusion-protocol-101" title="Robots Exclusion Protocol 101">an excellent post on SEOmoz</a>, there are two different kinds of directives: crawler directives and indexer directives.</p><p><span
id="more-520"></span><br
/> <strong>Crawler directives</strong><br
/> The <code>robots.txt</code> file only contains the so called Crawler directives, telling search engines, identified by their <code>User-agent:</code>, where they are not allowed to go by using <code>Disallow:</code> and where they <em>can</em> (and should) go by using <code>Allow:</code>, and by pointing them at a <code>Sitemap:</code>.</p><p>As Sebastian pointed out and explains thoroughly in <a
href="http://sebastians-pamphlets.com/standardization-of-rep-tags-as-robots-txt-directives/">another brilliant post</a>, pages that search engines aren't allowed to spider, can still show up in the search results, when they have enough links pointing at them. This basically means that if you want to <em>really</em> <a
href="http://www.seomoz.org/blog/12-ways-to-keep-your-content-hidden-from-the-search-engines">hide something from the search engines</a> and thus from people using search, <code>robots.txt</code> just isn't good enough.</p><p><strong>Indexer directives</strong><br
/> Indexer directives are directives that are, even with the birth of the X-Robots-Tag, set on a per page or even per element basis. Up until July 2007, there were two: the microformat <a
href="http://microformats.org/wiki/rel-nofollow">rel="nofollow"</a>, which means that that link should not pass authority / PageRank, and the <a
href="http://yoast.com/wordpress/meta-robots-wordpress-plugin/robots-meta-tags/">Meta Robots tag</a>.</p><p>With the Meta Robots tag, you can <em>really</em> prevent search engines from showing the pages you block in the search results. You can reach the same with the relatively new X-Robots-Tag HTTP header. If you don't know what an HTTP header is, I'd suggest reading the <a
href="http://en.wikipedia.org/wiki/HTTP">Wikipedia page on it</a>, but in short: look at it as the envelope around your content. This HTTP header is better than the meta robots tag for a couple of reasons, one of them is that you can send those headers for other documents too. So, let's get into some examples.</p><h2><a
title="examples" name="examples"></a>Example uses of the X-Robots-Tag</h2><p>If you want to prevent search engines from showing files you've generated with PHP, add the following in the header file:</p><pre>header("X-Robots-Tag: noindex", true);</pre><p>This would not prevent search engines from following the links on those pages, if you want to do that, do the following:</p><pre>header("X-Robots-Tag: noindex, nofollow", true);</pre><p>But doing it in PHP is probably not the easiest use for this kind of thing. I myself greatly prefer setting headers in Apache, when possible. Consider, for instance, preventing search engines from caching / showing a preview for all .doc files on your domain, you would only have to do the following:</p><pre>&lt;FilesMatch "\.doc$"&gt;
Header set X-Robots-Tag "index, noarchive, nosnippet"
&lt;/Files&gt;</pre><p>Or, if you'd want to do this for both .doc and .pdf files:</p><pre>&lt;FilesMatch "\.(doc|pdf)$"&gt;
Header set X-Robots-Tag "index, noarchive, nosnippet"
&lt;/Files&gt;</pre><p>Or another case, your <code>robots.txt</code> file itself is <a
href="http://www.google.com/search?hl=en&amp;q=allinurl%3A%22%2Frobots.txt%22" rel="nofollow">showing up in the search results</a>. Adding this to your Apache config or your <code>.htaccess</code> file would solve that:</p><pre>&lt;FilesMatch "robots\.txt"&gt;
Header set X-Robots-Tag "noindex"
&lt;/FilesMatch&gt;</pre><p>I had a slight uncomfortable feeling when writing this down, so I e-mailed <a
href="http://www.mattcutts.com/blog/">Matt Cutts</a> asking the following: "&lt;snip&gt; would that mean that you will still fetch it for robots.txt purposes, but won't show it in the index?". I'm waiting for him to answer, and will add his response here once I have it.</p><p><strong>Tools</strong><br
/> I've quickly created a <a
href="javascript:(function(){function%20read(url){var%20r=new%20XMLHttpRequest();r.open('HEAD',url,false);r.send(null);return%20r.getAllResponseHeaders();}alert(read(window.location))})();">bookmarklet</a> which shows all the headers for a page (works in Moz browsers only I think, and a <a
href="http://cdn.yoast.com/wp-content/uploads/2008/01/headerdetector.user.js" target="_blank" title="X-Robots-Tag HeaderDetector">Greasemonkey script</a> which pops up when a page is using an X-Robots-Tag header.</p><p><strong>Conclusion</strong><br
/> As you can see, if you combine the examples above with the stuff you can learn from for instance <a
href="http://www.askapache.com/htaccess/using-filesmatch-and-files-in-htaccess.html">AskApache's .htaccess tutorial</a>, the X-Robots-Tag HTTP header becomes a very powerful tool. Use it wisely and with caution, as you won't be the first to block your entire site by accident, but it's a great addition to your toolset if you know how to use it.</p><p><a
href="http://yoast.com/x-robots-tag-play/">Playing with the X-Robots-Tag HTTP header</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/x-robots-tag-play/feed/</wfw:commentRss> <slash:comments>31</slash:comments> </item> <item><title>How to remove www from your URL with mod_rewrite</title><link>http://yoast.com/how-to-remove-www-from-your-url-with-mod_rewrite/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-remove-www-from-your-url-with-mod_rewrite</link> <comments>http://yoast.com/how-to-remove-www-from-your-url-with-mod_rewrite/#comments</comments> <pubDate>Sun, 08 Apr 2007 20:56:17 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[SEO]]></category> <category><![CDATA[Serverside]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/how-to-remove-www-from-your-url-with-mod_rewrite/</guid> <description><![CDATA[<p>I got a hit today for the following search query: how do you get rid of the www in url. As you can see that hits on my article about removing PHPSESSID's, which isn't quite what the person was looking for I guess. Here's the code to 301 redirect the www version of your site [...]</p><p><a
href="http://yoast.com/how-to-remove-www-from-your-url-with-mod_rewrite/">How to remove www from your URL with mod_rewrite</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p>I got a hit today for the following search query: <a
href="http://www.google.com/search?q=how+do+you+get+rid+of+the+www+in+url&amp;start=0">how do you get rid of the www in url</a>. As you can see that hits on my article about <a
href="http://yoast.com/blog/how-to-get-rid-of-phpsessid-in-the-url-and-redirect/">removing PHPSESSID's</a>, which isn't quite what the person was looking for I guess. Here's the code to 301 redirect the www version of your site to the non-www version using Apache's mod_rewrite:</p><pre>RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]</pre><h2>Adding the www instead of removing it</h2><p>And, as requested in the comments, the code to <strong>add www</strong> to your domain name:</p><pre>RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com$1 [R=301]</pre><p><a
href="http://yoast.com/how-to-remove-www-from-your-url-with-mod_rewrite/">How to remove www from your URL with mod_rewrite</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/how-to-remove-www-from-your-url-with-mod_rewrite/feed/</wfw:commentRss> <slash:comments>42</slash:comments> </item> <item><title>Implementing a sitewide search function</title><link>http://yoast.com/implementing-a-sitewide-search-function/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=implementing-a-sitewide-search-function</link> <comments>http://yoast.com/implementing-a-sitewide-search-function/#comments</comments> <pubDate>Fri, 06 Apr 2007 09:32:26 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[Webdesign & development]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Serverside]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/implementing-a-sitewide-search-function/</guid> <description><![CDATA[<p>Those of you coming to this site more often might have noticed a small change in the search box. It's now implemented sitewide, and I've built a sitewide search functions using the Yahoo! API. It was quite nescessary because I found that people were searching for "sortable.zip" on the blog, and they wouldn't find anything [...]</p><p><a
href="http://yoast.com/implementing-a-sitewide-search-function/">Implementing a sitewide search function</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p>Those of you coming to this site more often might have noticed a small change in the search box. It's now implemented sitewide, and I've built a sitewide search functions using the <a
href="http://developer.yahoo.net/about">Yahoo! API</a>. It was quite nescessary because I found that people were searching for "sortable.zip" on the blog, and they wouldn't find anything since the pages for the <a
href="http://yoast.com/code/sortable-table/">sortable table script</a> are static.</p><p><strong>Keeping track of what people are searching for</strong><br
/> I had a few things to make sure while building this search function. First of all, I wanted to have the same info I get when I look at the statistics page for the <a
href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter WordPress plugin</a>. Secondly, I wanted to show more then just the post or page title. The last, but also very important demand I have is that it's fast. Well the first one was quite easy, I decided to put  the data into the table for the search meter plugin and just use that interface, instead of writing that myself. The function was basically adapted from the code of the plugin:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> save_search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$searchstring</span><span style="color: #339933;">,</span> <span style="color: #000088;">$numresults</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">global</span> <span style="color: #000088;">$table_prefix</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Save into the DB. Usually this will be a new query, so try to insert first</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">{$table_prefix}</span>searchmeter (terms,date,count,last_hits) VALUES ('<span style="color: #006699; font-weight: bold;">$searchstring</span>',CURDATE(),1,<span style="color: #006699; font-weight: bold;">$numresults</span>)&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$success</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$success</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE '<span style="color: #006699; font-weight: bold;">{$table_prefix}</span>searchmeter' SET count = count + 1, last_hits = <span style="color: #006699; font-weight: bold;">$numresults</span> WHERE terms = '<span style="color: #006699; font-weight: bold;">$searchstring</span>' AND date = CURDATE()&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$success</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p><strong>Constructing the Yahoo! API query</strong><br
/> The second thing wasn't too hard to do either, as Yahoo! returns a snippet with the searchresult for the query. The <a
href="http://en.wikipedia.org/wiki/Representational_State_Transfer"><abbr
title="Representational State Transfer">REST</abbr></a> query is constructed as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;site:yoast.com+&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$searchstring</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://search.yahooapis.com/WebSearchService/V1/webSearch?appid='</span><span style="color: #339933;">.</span><span style="color: #000088;">$yahooappid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;query='</span><span style="color: #339933;">.</span><span style="color: #000088;">$query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;output=php'</span><span style="color: #339933;">;</span></pre></div></div><p>The part <code>output=php</code> makes the API return serialized PHP, which, after calling <code>unserialize</code>, turns into a nice clean array, which you can then loop through to display the results.</p><p>The only thing left was adding the search box to my layout for the non-blog pages, and fixing the blog to look the same. In the theme I had to change the action URL of the searchform.php file to /search/, and there it was: my new site wide search function!</p><p>So far, it's all good. I've got a few things left, like building in paging so you can see more than 10 results. I've got one thing that bothers me though: it's a bit slow. Of course I could solve this by spidering my own site with something like <a
href="http://www.htdig.org/">ht://Dig</a>, but I think there ought to be a better solution... Perhaps you guys and girls know of one?</p><p><a
href="http://yoast.com/implementing-a-sitewide-search-function/">Implementing a sitewide search function</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/implementing-a-sitewide-search-function/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>PHP 301 redirects for Apache and IIS</title><link>http://yoast.com/php-301-redirects-apache-iis/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=php-301-redirects-apache-iis</link> <comments>http://yoast.com/php-301-redirects-apache-iis/#comments</comments> <pubDate>Mon, 02 Apr 2007 20:32:04 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[Serverside]]></category> <category><![CDATA[Webdesign & development]]></category> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/php-301-redirects-for-apache-and-iis/</guid> <description><![CDATA[<p>This one is just here for my own reference, because the default 302 status code just isn't good enough! PHP 301 for Apache: header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.example.com/newpage/"); exit; PHP 301 for IIS: header("Status: 301 Moved Permanently"); header("Location: http://www.example.com/newpage/"); exit;</p><p><a
href="http://yoast.com/php-301-redirects-apache-iis/">PHP 301 redirects for Apache and IIS</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p>This one is just here for my own reference, because the default 302 status code just isn't good enough!</p><p>PHP 301 for Apache:</p><pre>header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/newpage/");
exit;</pre><p>PHP 301 for IIS:</p><pre>header("Status: 301 Moved Permanently");
header("Location: http://www.example.com/newpage/");
exit;</pre><p><a
href="http://yoast.com/php-301-redirects-apache-iis/">PHP 301 redirects for Apache and IIS</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/php-301-redirects-apache-iis/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Convert underscores to dashes with Apache mod_rewrite</title><link>http://yoast.com/apache-rewrite-dash-underscore/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=apache-rewrite-dash-underscore</link> <comments>http://yoast.com/apache-rewrite-dash-underscore/#comments</comments> <pubDate>Sun, 25 Mar 2007 15:32:28 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[Serverside]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/apache-rewrite-dash-underscore/</guid> <description><![CDATA[<p>Update: (Aug 4 2007) the stuff below is no longer necessary, all major search engines now treat underscores and dashes exactly the same, as word separators! A year or so back, I was using underscores in my URL's on this site for spaces, and I decided to switch them to dashes, since several people, including [...]</p><p><a
href="http://yoast.com/apache-rewrite-dash-underscore/">Convert underscores to dashes with Apache mod_rewrite</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p><strong>Update:</strong> (Aug 4 2007) the stuff below is no longer necessary, all major search engines now treat underscores and dashes exactly the same, as word separators!</p><p>A year or so back, I was using underscores in my URL's on this site for spaces,  and I decided to switch them to dashes, since several people, including Matt Cutts, had blogged that this was "the way to go". Now at that time I just redirected all old URL's to new ones, which created like 30 lines in my Apache config, something I didn't really like...</p><p>This morning I took the time to find a more elegant solution, and the easiest one I could come up with is the following:</p><pre>RewriteCond %{REQUEST_URI} ^(.*)_(.*)/$
RewriteRule (.*)_(.*)/ http://yoast.com$1-$2/ [R=301]</pre><p>This will rewrite a single underscore to a single dash, using a 301 redirect. So if you have directories with four underscores, it will go through this rewrite four  times before reaching the final URL. I had some directories in which this was the case, and made sure it only had to redirect a maximum of two times by adding the following lines above it:</p><pre>RewriteCond %{REQUEST_URI} ^(.*)_(.*)_(.*)/$
RewriteRule (.*)_(.*)_(.*)/ http://yoast.com$1-$2-$3/ [R=301]</pre><p>You could add even more lines like these if need be, I'd make sure that no more than two redirects are needed to rewrite the underscores into dashes.</p><p>The "/" on the end of the RewriteCond is there to make sure this is a directory, and not a file, since I've got quite a few images with underscores in the names and didn't want to bother renaming them.</p><p><a
href="http://yoast.com/apache-rewrite-dash-underscore/">Convert underscores to dashes with Apache mod_rewrite</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/apache-rewrite-dash-underscore/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Trailing double forward slashes in URL&#8217;s in the SERPs&#8230;</title><link>http://yoast.com/trailing-double-forward-slashes-in-urls-in-the-serps/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=trailing-double-forward-slashes-in-urls-in-the-serps</link> <comments>http://yoast.com/trailing-double-forward-slashes-in-urls-in-the-serps/#comments</comments> <pubDate>Sat, 17 Mar 2007 19:18:36 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[Serverside]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/trailing-double-forward-slashes-in-urls-in-the-serps/</guid> <description><![CDATA[<p>This query gives a result I hadn't seen before (image), the same page was indexed with both a single trailing forward slash, which is of course normal, and with a double trailing forward slash... This is of course a duplicate content issue, especially when people link to the double slash one by accident. The fix [...]</p><p><a
href="http://yoast.com/trailing-double-forward-slashes-in-urls-in-the-serps/">Trailing double forward slashes in URL&#8217;s in the SERPs&#8230;</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p><a
href="http://www.google.com/search?q=site:http://yoast.com/code/greasemonkey/statistics-detector/&amp;hl=en&amp;safe=off&amp;filter=0" target="_blank">This query</a> gives a result I hadn't seen before (<a
href="http://yoast.com/blog/wp-content/uploads/2007/03/doubleslash.png" title="double trailing forward slash in Google SERPs">image</a>), the same page was indexed with both a single trailing forward slash, which is of course normal, and with a double trailing forward slash... This is of course a duplicate content issue, especially when people link to the double slash one by accident. The fix for it in Apache is quite easy, just add this to your server config or htaccess:</p><pre>RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//$
RewriteRule . http://yoast.com%1/ [R=301]</pre><p><a
href="http://yoast.com/trailing-double-forward-slashes-in-urls-in-the-serps/">Trailing double forward slashes in URL&#8217;s in the SERPs&#8230;</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/trailing-double-forward-slashes-in-urls-in-the-serps/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Changing your permalink structure</title><link>http://yoast.com/changing-your-permalink-structure/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=changing-your-permalink-structure</link> <comments>http://yoast.com/changing-your-permalink-structure/#comments</comments> <pubDate>Tue, 03 Oct 2006 14:16:17 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[WordPress]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[permalinks]]></category> <category><![CDATA[SEO]]></category> <category><![CDATA[Serverside]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/changing-your-permalink-structure/</guid> <description><![CDATA[<p>I recently changed the permalink structure of this WordPress blog, going from /%year%/%monthnum%/%day%/%postname%/ (WordPress default i think) to the much more elegant and simple /%postname%/. This is very cool ofcourse, both because it's simpler and SEO wise, but on an existing blog, this leaves you with lots of links that point to the wrong URL. [...]</p><p><a
href="http://yoast.com/changing-your-permalink-structure/">Changing your permalink structure</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></description> <content:encoded><![CDATA[<p>I recently changed the permalink structure of this WordPress blog, going from <code>/%year%/%monthnum%/%day%/%postname%/</code> (WordPress default i think) to the much more elegant and simple <code>/%postname%/</code>. This is very cool ofcourse, both because it's simpler and SEO wise, but on an existing blog, this leaves you with lots of links that point to the wrong URL. If you're running your blog on Apache, the solution is quite simple, if you can tweak your <code>.htaccess</code> file or your Apache config.</p><p>The solution can be found in one single RedirectMatch line. This line should be placed above the WordPress code, or in the Apache config. The line is the following:</p><div
class="wp_syntax"><div
class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RedirectMatch</span> <span style="color: #ff0000;">301</span> /([<span style="color: #ff0000;">0</span>-<span style="color: #ff0000;">9</span>]+)/([<span style="color: #ff0000;">0</span>-<span style="color: #ff0000;">9</span>]+)/([<span style="color: #ff0000;">0</span>-<span style="color: #ff0000;">9</span>]+)/(.*)$ 
http://www.<span style="color: #00007f;">example</span>.com/$<span style="color: #ff0000;">4</span></pre></div></div><p>This matches every URL which starts with  a date, and permanently redirects it to the new URL for this post. Ofcourse you could be running your blog in a subdirectory, like I am, in that case, the line would be:</p><div
class="wp_syntax"><div
class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RedirectMatch</span> <span style="color: #ff0000;">301</span> /subdir/([<span style="color: #ff0000;">0</span>-<span style="color: #ff0000;">9</span>]+)/([<span style="color: #ff0000;">0</span>-<span style="color: #ff0000;">9</span>]+)/([<span style="color: #ff0000;">0</span>-<span style="color: #ff0000;">9</span>]+)/(.*)$
http://www.<span style="color: #00007f;">example</span>.com/subdir/$<span style="color: #ff0000;">4</span></pre></div></div><p>This way, all your incoming links will still work, and thus count for SearchEngines <em>and</em> you have the benefits of the new URL structure.</p><p><a
href="http://yoast.com/changing-your-permalink-structure/">Changing your permalink structure</a> is a post from <a
href="http://yoast.com/about-me/">Joost de Valk</a>&#39;s <a
href="http://yoast.com">Yoast - Tweaking Websites</a>.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on <a
href="http://yoast.com/wordpress-hosting/">WordPress hosting</a>!</p>]]></content:encoded> <wfw:commentRss>http://yoast.com/changing-your-permalink-structure/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc (request URI is rejected)
Database Caching 6/14 queries in 0.015 seconds using apc
Content Delivery Network via cdn.yoast.com

Served from: yoast.com @ 2010-09-02 15:17:07 -->