Subdomain redirect
A couple of months ago, Matt released a simple plugin to redirect one’s site from the www. to no-www. I.e., If someone types http://www.ckunte.com in browser, they’d get redirected to http://ckunte.com. Matt’s code uses substr to strip the www. part of the URI (four characters, including the dot).
How does this interest me? Well, it’s nice to get an accurate report of stats rather than the same domain fragmented based on user’s query. In addition, I continue to get hits from my old address: http://chetan.ckunte.com. I wanted to change that and so, I did. Simple really.
While www. is 4 characters, chetan. is 7 characters. So, my updated plugin code based on Matt’s no-www looks like this:
<?php/*Plugin Name: No ChetanPlugin URI: http://ckunte.com/Description: Chetan subdomain address is redirected to root.Author: Chetan Kunte based on Matt Mullenweg no-wwwVersion: 1.0Author URI: http://ckunte.com/*/if ( !strstr( $_SERVER['HTTP_HOST'], 'chetan.' ) )return;header('HTTP/1.1 301 Moved Permanently');header('Location: http://' . substr($_SERVER['HTTP_HOST'], 7) . $_SERVER['REQUEST_URI']);exit();?>- Download this example: /inputfiles/subdomain-redirect.txt
(Seriously, no more posts after this for at least another 3-weeks, as I have been saying.)
Update: Did I mention that this technique also redirects all permalinks with old address to the new one?