Ajax software
Free javascripts
↑
Main Page
This says that if any request designated to this site comes in with something other than
www.example.com
,
it should be changed to that. This is a slightly broader definition, and may or may not be desirable. It will
also redirect any other domains that resolve to your site to
www.example.com
.
Please note: It is
not
a good idea to use a site removal tool to remove the
example.com
pages for a site,
even after these changes have been applied! This can result in complete site removal. Matt Cutts of Google
says “If you remove one of the www vs. non-www hostnames, it can end up removing your whole
domain for six months. Definitely don’t do this” (
http://www.mattcutts.com/blog/seo-advice-
url-anonicalization/
). Instead, simply 301 the non-desirable domain to the desirable one, and the
problem should slowly be resolved over time.
URL Canonicalization: /index.php versus /
Unfortunately, the concept of index pages (
index.php
,
Default.aspx
, and so on) causes yet another
duplicate content problem. If no file name in a directory is provided to a web server, the “index” page
is typically provided by default, but without redirection to this page. The problem arises when both
URLs are linked, either internally or from other sites. This results in the duplicate content because there
are two URLs that are used to access the same content. Strictly speaking, neither URL is more correct,
though shorter URLs are usually desirable, and hence we favor
/
over
/index.php
.
The solution is similar to the one for the
www.example.com
vs.
example.com
issue. You must use a 301
redirect to the containing directory whenever you get a request for a file path ending in
index.php
or
index.html
. The redirection code can simply be implemented using a mod_rewrite rule or in PHP.
Using mod_rewrite, you’d just need to add these lines to the
.htaccess
file:
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html)\ HTTP
RewriteRule ^(.*)index\.(php|html)$ /$1 [R=301,L]
After making this change, trying to load
http://seophp.example.com/index.php
should redirect
you to
http://seophp.example.com/
.
Alternatively, you can take care of the redirection in PHP code. You do that in the next exercise.
Eliminating index.php
1.
Add a file named
index.php
to your
seophp
folder, with the following code:
<?php
// redirect the current request if necessary
require_once ‘include/url_redirect.inc.php’;
// redirect requests to index.php and index.html to the root
fix_index_url();
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<html>
92
Chapter 4: Content Relocation and HTTP Status Codes
c04.qxd:c04 10:40 92
Ajax software
Free javascripts
→