<?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/cat/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>Change domain, and warn your visitors</title><link>http://yoast.com/change-domain-name/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=change-domain-name</link> <comments>http://yoast.com/change-domain-name/#comments</comments> <pubDate>Wed, 09 Jun 2010 08:25:32 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[Serverside]]></category> <category><![CDATA[Hosting]]></category> <category><![CDATA[redirect]]></category><guid
isPermaLink="false">http://yoast.com/?p=2416</guid> <description><![CDATA[<p>When you change domains, for instance using my moving WordPress to a new domain guide, you'll usually redirect your visitors with something looking like this: Redirect 301 / http://new.example.com/﻿ The only issue with this is that people might not notice that you've moved to a new domain, and thus might not update their links to [...]</p><p><a
href="http://yoast.com/change-domain-name/">Change domain, and warn your visitors</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>When you change domains, for instance using my <a
href="http://yoast.com/move-wordpress-blog-domain-10-steps/">moving WordPress to a new domain</a> guide, you'll usually redirect your visitors with something looking like this:</p><div
class="wp_syntax"><div
class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">Redirect</span> <span style="color: #ff0000;">301</span> / http://new.<span style="color: #00007f;">example</span>.com/﻿</pre></div></div><p>The only issue with this is that people might not notice that you've moved to a new domain, and thus might not update their links to you. As <a
href="http://www.mattcutts.com/">Matt Cutts</a> confirmed a while back that <a
href="http://searchengineland.com/cutts-redirects-dont-pass-full-pagerank-more-takeaways-38064">301 redirects do not pass full PageRank</a>, and they seem to take a hell of a time to kick in these days, that's somewhat of an issue: we'd rather have people update their links.</p><h2 id="proper-redirect">The proper redirect</h2><p>So we want to tell people that you've moved to a new domain, but only people who came through <em>old</em> links to your site. And we still want to keep that 301 redirect in place, to preserve as much of the value from the old site as we can.</p><p>So, what if we redirected to <code>http://new.example.com/#moved</code>? The search engines don't care about anything from the hash onwards, so the value of the redirect would still be maintained. We could then use javascript to detect the value of the hash tag, and display a notice to our visitors.</p><p>There's an issue with that as well though: with the <code>redirect 301 /</code> line above, we redirected everything after /, to <code>new.example.com/</code>, so for instance <code>/test/</code> would be redirected to <code>new.example.com/test/</code>. If we added <code>#moved</code> to the end of that URL, we would end up with new.example.com/#moved/test/ and that wouldn't work. So we'll need to make a bit of a fancier redirect:</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> /(.*)? http://new.<span style="color: #00007f;">example</span>.com/$<span style="color: #ff0000;">1</span><span style="color: #adadad; font-style: italic;">#moved</span></pre></div></div></p><p>That should work. Notice though that when you have code in place adding a / to the end of your URL's if not existent, that code should conserve any hash tags in the URL.</p><h2 id="domain-move-message">Showing the domain move message</h2><p>So now, let's move on to the javascript part to actually show people a "we've moved" message, which is actually pretty simple. You create a <code>div</code> with the message you want to show, and put it in your footer, something like this:</p><div
class="wp_syntax"><div
class="code"><pre class="htm" style="font-family:monospace;">&lt;div id=&quot;domainmovemsg&quot; style=&quot;display:none;&quot;&gt;
  We've moved from old.example.com to new.example.com, 
  please update your feeds &amp; links!
&lt;/div&gt;</pre></div></div><p>As you can see, we default it to <code>display: none;</code> so not everybody sees it, and then you add this tiny snippet of javascript, also in the footer of your page, after you've loaded the <code>div</code> above:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">location</span>.<span style="color: #660066;">hash</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'#moved'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domainmovemsg'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h2 id="example">Example code</h2><p>I've coded an example of this with some more styling etc., which you can find <a
href="http://yoast.com/code/domain-move/">here</a>. If you want to see it in action immediately, you'll have to click <a
href="http://yoast.com/code/domain-move/#moved">this link</a>.</p><p><a
href="http://yoast.com/change-domain-name/">Change domain, and warn your visitors</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/change-domain-name/feed/</wfw:commentRss> <slash:comments>7</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>PHP-APC: Speed up your web applications!</title><link>http://yoast.com/php-apc-speed-web-applications/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=php-apc-speed-web-applications</link> <comments>http://yoast.com/php-apc-speed-web-applications/#comments</comments> <pubDate>Sun, 08 Apr 2007 08:08:25 +0000</pubDate> <dc:creator>Joost de Valk</dc:creator> <category><![CDATA[Serverside]]></category> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://www.joostdevalk.nl/blog/php-apc-speed-web-appilcations/</guid> <description><![CDATA[<p>As regular readers of this blog might know I have written quite some tools using the different API's of search engines, and always found them quite useful. When I was implementing my sitewide search function, one of the things that bothered me that it was a bit slow. I knew that I had seen some [...]</p><p><a
href="http://yoast.com/php-apc-speed-web-applications/">PHP-APC: Speed up your web applications!</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>As regular readers of this blog might know I have written quite some tools using the different API's of search engines, and always found them quite useful. When I was implementing my <a
href="http://yoast.com/blog/implementing-a-sitewide-search-function/">sitewide search function</a>, one of the things that bothered me that it was a bit slow. I knew that I had seen some caching implementations on the <a
href="http://developer.yahoo.com/php/">Yahoo PHP developer center</a>, but I hadn't bothered up till then to look at them a bit better.</p><p>Now I did, and I found the <a
href="http://developer.yahoo.com/php/samples/cache/cacheAPC.txt">cacheAPC</a> example to be very, very easy. It relies on the <a
href="http://php.net/apc">Alternative PHP Cache</a>, an opcode cache <a
href="http://pecl.php.net/">PECL</a> extension for PHP. I wrote two functions, which I then put in to all my pieces of code which I've published that use a lot of calls to the different API's. The first is <code>curlopen</code>, the function I use to open connections:</p><pre>function curlopen($request) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $request);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 100);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	$results = curl_exec ($ch);
	curl_close($ch);
	return $results;
}</pre><p>The second one is the actual cache function, look at how easy it is:</p><pre>function request_cache($url, $ttl) {
	if(!$doc = apc_fetch($url)) {
		$doc = curlopen($url);
		if ($doc === false) return false;
		apc_store($url,$doc, $ttl);
	}
	return $doc;
}</pre><p>It basically does three things:</p><ol><li>It looks if the requested resource is already in the cache, and if it is, it fetches that;</li><li>If it's not, it opens it through <code>curlopen</code> and stores it in the cache;</li><li>It returns the requested data;</li></ol><p>As you can see the request_cache function takes two parameters: the request url and the <a
href="http://en.wikipedia.org/wiki/Time_to_live">TTL</a>, which, in seconds, determines how long that resource should be cached. Now if you request a PageRank for a URL, it's fairly safe to set this to 24 hours, and you can see how much requests this saves!</p><p><a
href="http://yoast.com/php-apc-speed-web-applications/">PHP-APC: Speed up your web applications!</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-apc-speed-web-applications/feed/</wfw:commentRss> <slash:comments>15</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> </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 5/13 queries in 0.018 seconds using apc
Content Delivery Network via cdn.yoast.com

Served from: yoast.com @ 2010-09-02 15:40:15 -->