Resolve Canonical URL Looping in Apache

January 31, 2006

Interesting… I’ve come in contact with the canonical redirect issue before. Mostly it’s an issue of Apache 1.3 and redirecting the no-www version of a website to the www version (Apache 2.0, I’ve noticed, does a much better job of not getting caught in the loop), but redirecting index.php to root when Apache calls index.php is somewhat of a problem. Luckily, Oatmeal of SEOmoz has your solution:

  1. Copy index.php to another filename that is not set as a DirectoryIndex by apache, for this example we’ll be using sitehome.php
  2. Create an apache DirectoryIndex directive for your document root.
    Set it to sitehome.php. Do not set the directive on a server-wide level
    otherwise it may cause problems with other folders that still need to
    use index.php as a directory index.
    Put this in an .htaccess file in your document root: DirectoryIndex sitehome.php Or if you aren’t using per-directory context files, put this in your httpd.conf
    <Directory /your/document/root/examplesite.com/>
      DirectoryIndex sitehome.php
    </Directory>
  3. Clear out the contents of your original index.php file. Insert this line of code:
    <? header("Location: http://www.example.com"); ?>

 

About

Welcome to the Topositionseo blog, your source for SEO news, information and interpretation. The Topositionseo blog is maintained by Dustin Frelich, Nobis Interactive's in-house search guru. His views and opinions do not necessarily reflect those of his employer.

Search

Subscribe

Archives