
Originally Posted by
wkenny
The search engines would probably not index the pages because of the re-direct. Yahoo show how they handle re-directs and, unless I've misinterpreted, when a re-direct is to a page in the same domain they index the referring page rather than the target page
I should think you have misunderstood. The redirect will either be internal (the Web server itself chooses a different file) or via a HTTP redirect. A search engine wouldn't even know about the former, and it would be completely broken if it ignored the latter.
Search engines will not process "redirects" implemented through client-side scripts, and they are wary of meta element "redirects". The latter can easily be abused.
Can you post a link to where you read this information?
Text on one of the links from the page you referred me to says " It is easy to directly pre-generate a page to its static form" but does not say how. This is what I need.
What can be done is to check the modification time of each source that makes up a document, and compare it against the time of the generated document (if it exists). If the generated document is older than the newest source, it is regenerated. Eventually, a temporary redirect is returned that refers to the generated version.
Something along the lines of:
PHP Code:
<?php
/* This file name needs to be determined somehow. The name of the PHP file is sensible, but not
* necessarily appropriate. Do no use an absolute path (without making the necessary changes,
* below).
*/
$destination = '...';
/* A list of files used to construct the document. */
$sources = array('header.fragment', 'content.fragment', 'footer.fragment');
if (!file_exists($destination . '.lock')) {
touch($destination . '.lock');
}
$lockFile = fopen($destination . '.lock', 'r');
flock($lockFile, LOCK_SH);
if (isStale($destination, $sources)) {
/* Upgrade lock before writing. */
flock($lockFile, LOCK_EX);
$destinationFile = fopen($destination, 'w');
ob_start();
/* Output contents... */
fwrite($destinationFile, ob_get_contents());
fclose($destinationFile);
ob_end_clean();
}
flock($lockFile, LOCK_UN);
fclose($lockFile);
/* Change the domain name as necessary. */
$destinationUri = 'http://www.example.com' . rtrim(dirname($_SERVER['PHP_SELF']), '/')
. '/' . $destination;
header('Location: ' . $destinationUri);
?>
<!DOCTYPE html "-//W3C//DTD HTML 4.01/EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Continue to <?php echo $destinationUri; ?></title>
</head>
<body>
<p>Please continue to <a href="<?php echo $destinationUri; ?>"><?php echo $destination; ?></a>.</p>
</body>
</html>
<?php
function isStale($destination, $sources) {
if (!file_exists($destination)) {
return true;
}
$generationTime = filemtime($destination);
foreach ($sources as $source) {
if ($generationTime < filemtime($source)) {
return true;
}
}
return false;
}
?>
In principle it's simple, but it can get awkward with many sources without some abstraction. One also needs to check that it's less resource-consuming to test the modification times than it is to generate the document (as well as cache-related headers like ETags, and Last-Modified, and Content-Length to facilitate persistent connections).
Mike
Bookmarks