JavaScript Editor Ajax software     Free javascripts 



Main Page

<head>
<title>SEO Egghead: SEO for Nerds</title>
</head>
<body>
<h1>Welcome to SEO Egghead!</h1>
</body>
</html>
2.
Add this code to your
url_redirect.inc.php
file:
<?php
// load the URL factory library
require_once ‘url_factory.inc.php’;
// redirect requests to index.php and index.html to the root
function fix_index_url()
{
// if the request is for index.php we redirect to ./
if (preg_match(‘#(.*)index\.(html|php)$#‘, $_SERVER[‘REQUEST_URI’], $captures))
{
// perform a 301 redirect to the new URL
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: ‘ . $captures[1]);
}
}
...
?>
3.
Load
http://seophp.example.com/index.php
, and expect to be redirected to
http://seophp.example.com/
(see Figure 4-5).
The code is pretty straightforward. You started by creating a very simple version of
index.php
., which
contains only a title. However, what’s special about this
index.php
file is that in the beginning it loads the
url_redirect.inc.php
script. This script checks if the page was accessed through a URL that ends either
with
index.php
or
index.html
:
// if the request ends in index.php we redirect to the same path without it.
if (preg_match(‘#(.*)index\.(html|php)$#‘, $_SERVER[‘REQUEST_URI’], $captures))
Figure 4-5
93
Chapter 4: Content Relocation and HTTP Status Codes
c04.qxd:c04 10:40 93


JavaScript Editor Ajax software     Free javascripts