2008-06-26 @ admin
I've been working hard on writing a book about the Stripes framework with The Pragmatic Programmers. Hopefully, I'll have something to show for soon. Stay tuned!
One more update today...
Part of SEO according to SEO Forum is making sure that all Google PR goes to the only one version of a page. So redirecting index.php to root is one important part of SEO'ing a website properly. The same is true for any other index pages within your website.
Have a try on your website! What is the file that is used for your index page - index.php, or index.html, or index.asp etc. Try using http://www.stripesbook.com/index.php - another of my blogs. Try accessing this site with index.php in the url. See that the url gets redirected to the http://www.stripesbook.com/ url.
Within your website, you should only refer to the index page as <a xhref="/"> not <a xhref="index.php">. But because you could inadvertently link to index.php, or certainly someone else could link to your website with the longer url, you are wise to do a redirect from one to the other (please excuse the xhref part, something up with my wordpress. Anyone know the fix?)
So how do you do it?
I have not yet been able to do the redirection via htaccess, but if you add the following to your index.php file, it does the trick nicely. For blogs, go to your templates directory, and you can add the code to the start of your index.php file in there. Works a treat.
Code to add to index.php:
if(preg_match("/[index.php]$/",$_SERVER[REQUEST_URI]))
{
$url="http://".$_SERVER[HTTP_HOST].preg_replace("/(index.php)$/","",$_SERVER[REQUEST_URI]);
$sapi=php_sapi_name();
if (PHP_VERSION >= '4.3.0')
{
header("Location: $url", 0, 301);
}
else if ($sapi == 'cgi' OR $sapi == 'cgi-fcgi')
{
header("Location: $url");
// Call the status header after Location so we are sure to wipe out the 302 header sent by PHP
header('Status: 301 Moved Permanently');
}
else
{
header("Location: $url");
header('HTTP/1.1 301 Moved Permanently');
}
}