Last-Modified and If-Modified-Since HTTP Headers

By far, the most popular among webmasters and the internet community, Google Sitemaps are an essential for the web today.

Moderator: MaxPowers

last modified

Postby caffesolo » February 25th, 2007, 11:14 am

our automapit interface says that our server does not support last modified, where do i set this up, on the server or in the php?



pz
caffesolo
 
Posts: 9
Joined: July 15th, 2006, 5:43 pm

Postby MaxPowers » February 25th, 2007, 12:15 pm

This is something that your server 'ought' to send across in the HTTP Headers as our spider connects to your server. On Apache, this will usually work by default if you have true HTML pages. If it goes through the PHP interpreter (uses PHP code) it will not report this information and you will see the error about not supporting Last-Mod.

I have written a script that will get you most of the way there...

ServHead is what I call it. What it does is to read the lastmod time from the file on your server and insert it into the HTTP headers for your webpage.

While this code was originally taken from some long-forgotten two-liner as an example on someones website, it has been reworked a number of times to help improve it and round it out some.

It is setup as-is to work with static files written in PHP, but could easily be converted for template system that creates pages entirely from your database as long as your CMS has a database field for when a document was last modified. The code is commented where you would need to add logic to check your database.

This script also helps your pages to support the If-Modified-Since header that Google uses to skip a page that hasn't changed since their last check. This saves both you and them some bandwidth and allows them to check your next URL on their list a little sooner.

In order to use it, include it as the first line of your code before anything is output to the browser (including empty spaces) such as...

<?php include("servhead.php");?>

You can use the HTTP Header Checker at AutoMapIt to see if your headers are coming out properly and using the Last-Modified header.

Of course, if you want the benefit, but don't want to deal with the particulars of getting this setup correctly, I can always install it for you for a small fee.

Google Webmaster Guidelines does suggest that your server should support the Last-Modified and If-Modified-Since headers, but I don't exactly see better ranking from doing this all by itself. What I do see is reduced bandwidth and faster indexing/re-indexing of your site since many pages wouldn't be updated regularly and Google can just skip those to get to the ones that have considerable amounts of fresh, new content quicker and easier.
MaxPowers
Site Admin
 
Posts: 233
Joined: May 27th, 2006, 4:40 pm

Postby webwidget » September 19th, 2007, 6:39 am

I have just started with automapit and have my sitemap set up and uploaded via the auto ftp facility.

I am interested to implement a dynamic database solution for category and product pages generated by osCommerce pages on my web site http://www.footdetox.uk.com

I can forsee that I will need to write in the current date/time when I modify a category or product page but it would be useful to see an example of how to read this value from a mysql database and use it in the script servhead.php

Thanks,
WebWidget
webwidget
 
Posts: 12
Joined: September 18th, 2007, 5:27 pm

Postby MaxPowers » September 19th, 2007, 10:28 am

This may likely require a bit more magic than I can explain here, but if you are good at PHP/MySQL, you should be able to follow along...


Your CMS (osCommerce) may already timestamp when products were edited and/or when they were first created. If not, you can get it setup so that the timestamps are automatic when the page is updated (meaning less to do later). Whether these timestamps come standard or not, you are correct in the idea that they need to be there.

There is a line in the servhead.php file that reads similar to...

$hmtime = @filemtime($sri);

and it's job is to find the time (Unix Timestamp, seconds since epoch) that the file was last modified. This is the one line that needs to read the last-mod time from your database.

So, depending on whether your page was 'last' or 'first' modified recently, grab that timestamp, convert to Unix timestamp, assign to $hmtime.

The code in my script before the $hmtime line is designed to grab the URL and narrow it down to a file name for checking. Change this to look up the requested URL in your database where you will also find the lastmod time.

If you would like to contract me to 'make this happen' instead of doing it yourself, please email me using the support form at AutoMapIt and I will be able to do this for you.
Last edited by MaxPowers on September 24th, 2007, 3:48 pm, edited 1 time in total.
MaxPowers
Site Admin
 
Posts: 233
Joined: May 27th, 2006, 4:40 pm

Tweaking servhead.php.

Postby maclin » September 24th, 2007, 3:23 pm

The first time I uploaded and called the script (servhead.php) from my main page, it produced an error. Then, I looked inside the script and noticed that it was referring to my main page as "index.html." However, I was using "index.php" as my main page!

So, I just changed the call from "index.html" to "index.php" inside the script, uploaded it, and voila . . . no errors!

Thanks, I appreciate the effort you put into writing the script. As for its SEO value via Google, I think every little bit helps. :D
maclin
 
Posts: 7
Joined: September 19th, 2007, 4:14 am
Location: Ohio

Postby MaxPowers » September 24th, 2007, 3:54 pm

This probably does not help SEO directly, but it does help Google to crawl your site more efficiently. I know that I appreciate it since I added support for If-Modified-Since in my own crawlers. It saves loading full pages that haven't been changed since the last run. Google says they like it when you do this, but I don't think it will cause an increase in ranking.

Then again, if I had to crawl every page from over 8-Billion websites, I'd prefer those who help me save time and bandwidth ~just a little~

By default, the servhead.php only works with static files that are passed through the PHP interpreter... an actual file that uses PHP code. URL rewrites and pages generated entirely from a database (like forums, shopping carts, and blogs) need additional work to map the last modified time from your applications database. Explaining how to do this is outside the scope of this forum and depends on too many factors to present a how-to guide.
MaxPowers
Site Admin
 
Posts: 233
Joined: May 27th, 2006, 4:40 pm


Return to Google Site Map

Who is online

Users browsing this forum: No registered users and 0 guests

cron