Can .htaccess test for If-Modified-Since?

Posted on 2009-02-23
Last Modified: 2012-05-06
Can I use .htaccess to test if a browser sends this to in the header to the server:  
      If-Modified-Since: XXXXXXXXX GMT

and if so redirect the visitor to:
Question by:hankknight
    LVL 27

    Expert Comment

    Yes, of course
    RewriteEngine on
    # check
    RewriteCond %{HTTP:If-Modified-Since} ^(.+)
    # and pass as query strng q=
    RewriteRule !^304\.php$ /304.php?q=%1 [L]

    Open in new window

    LVL 16

    Author Comment

    caterham_www, I think you clearly understand what I am trying to do.

    If a server has already sent a file or an image I do NOT want to send it again.  Instead I want to tell them to stop wasting time and bandwidth by sending them a 304 header.

    Will this work the way I intend it to?  Will it save website visitors time and my server bandwidth?

    After giving my last question some thought, do you think it will work about as good as your ideas to modify and  recompiling the mod_rewrite.c module or make a custom Apache module?
       // 304.php
       header('HTTP/1.1 304 Not Modified');

    Open in new window

    LVL 27

    Accepted Solution

    Using a module is of course the fastest way, followed by the RewriteMap external program approach (which is loaded once at server startup) and followed by a processing of a script within a content handler.

    Serving static files is pretty fast of course with sendfile (EnableSendfile). Until some point the downloading procedure of a small static file might be faster than processing a file in a content handler to issue a  304 by script.

    > Will this work the way I intend it to?

    Yes, you can do that within a php script as well, but there must not be any output (e.g. a blank line above of <? or below the closing ?>), of course. I'll post a small perl approach to the other thread.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now