homepage Welcome to WebmasterWorld Guest from 23.20.220.61
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
last modified headers
Is there a simple line I can add to my .htaccess file
RedWine




msg:3947137
 7:30 pm on Jul 6, 2009 (gmt 0)

I have sites with both .shtml and .php files. I have read that because these are dynamic files, a "last modified" date is not sent in the header.

I would like to make sure I send this so that my site/page is not spidered if it has not been updated. I would like to add a line to my .htaccess file to do this and am willing to change this this whenever I update my site. Will something like this work:

header set last-modified "Sun Jul 06 00:29:00 EDT 2009"

Does it matter where I put it in the .htaccess file (beginning/end)... any help/suggestions would be most appreciated!

 

jdMorgan




msg:3947150
 7:45 pm on Jul 6, 2009 (gmt 0)

The usual solution is to have your PHP script send the Last-Modified header, since you can use the script itself to read your database to find out when the last change was made (assuming that you use a Database). If not, the script can look at it's own last-modified date, by querying the filesystem.

So, you can use .htaccess, and make the changes manually, but that's not really the 'best' way to do it,

Jim

RedWine




msg:3947187
 8:42 pm on Jul 6, 2009 (gmt 0)

Thanks for the feedback. I understand what you are saying, but the PHP script method consumes server resources... on a small site that gets alot of traffic (and also does not change more than once a week), the .htaccess is a good way to go I think? In any case, to do the last_modified date in the header via the .htaccess file is:

header set last-modified "Sun Jul 18 00:32:50 EDT 2004"

Is the line above the best way to do it via the .htaccess file (given that the .htaccess file is the way you want to do it)?

jdMorgan




msg:3947195
 9:06 pm on Jul 6, 2009 (gmt 0)

I'd like to point out that *any* PHP code consumes server resources, as does .htaccess code. So why you would use PHP to generate an HTML page but not to report its last-modified date is somewhat incomprehensible to me.

As for the "Header set" line, yes, that should work -- assuming that you enclose it in an appropriate <Files> or <FilesMatch> container.

Order of .htaccess directives does not matter, except among directives handled by the same Apache module. For example, if you have both mod_headers code and mod_rewrite code, then regardless of their sequence in the .htaccess file, either all mod_headers directives will be executed first, or all mod_rewrite directives will be executed first, and then all directives handled by the other module will be executed. So execution is per-module, and not in strict directive-by-directive order. Module execution order is determined by the server configuration, or by an internal priority mechanism, depending on your server version. As a result, it makes no difference where you put the "Header set" in your file, unless there is a conflict or 'overlap' with another mod_headers directive.

Jim

Caterham




msg:3947230
 9:55 pm on Jul 6, 2009 (gmt 0)

BTW:

"Sun Jul 18 00:32:50 EDT 2004"

is invalid as a HTTP-date.

Last-Modified is defined as "Last-Modified" ":" HTTP-date (rfc2616 section 14.29)

HTTP-date is defined in rfc2616, section 3.3.1:
All HTTP date/time stamps MUST be represented in Greenwich Mean Time
(GMT), without exception. For the purposes of HTTP, GMT is exactly
equal to UTC (Coordinated Universal Time). This is indicated in the
first two formats by the inclusion of "GMT" as the three-letter
abbreviation for time zone, and MUST be assumed when reading the
asctime format. HTTP-date is case sensitive and MUST NOT include
additional LWS beyond that specifically included as SP in the
grammar.

The ANSI C asctime() format you're using does not include a time zone in its date string as a HTTP-date.

RedWine




msg:3947249
 10:22 pm on Jul 6, 2009 (gmt 0)

Thanks again for the help, also thanks for the information about the GMT and the date format.

As why I would use PHP to generate an HTML page but not to report its last-modified date... err I did not want to get into that.

The short explanation is that it is not .php code, its .asp code that has been moved to an apache server. I did not want to rewrite as .php specifically as .php because it would break all the links pointing to specific .asp pages. Further the .asp code does not have any asp script in it (not since it moved to the new apache server anyway), however it does use server side include functionality.

The simple answer was to have files with .asp extension processed as .php files. So wahhhlaaa... I have php pages with no php code/script in them... my situation.

[edited by: RedWine at 10:34 pm (utc) on July 6, 2009]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved