httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joey Hewitt <>
Subject Re: [users@httpd] Sending PHP-generated file Vs. plain text
Date Sun, 16 May 2004 18:31:30 GMT
Quoting Joshua Slive <>:
> On Sat, 15 May 2004, Joey Hewitt wrote:
> >   The problem is it looks like Apache is recognizing the .txt file before
> it
> > sees the .php file.  If I type the URL in my address bar with the .php on
> the
> > end, it works, but if I don't include an extension, I get the text file.
> >   If I can't find out how to make Apache recognize the .php file, I can
> move the
> > text file out of the DocumentRoot and it will work fine for me.  (After
> all,
> > does anyone set their browser to only Accept text/plain these days anyways?
> :)
> > )
> >   I realize that .php is a sort of generic extension in the sense that you
> can
> > use PHP to serve any type of data.  Indeed, it seems Apache uses PHP as a
> > "last-ditch attempt" to fulfill requests, because if I give it the same
> Accept
> > parameters my browser does but without text/plain, it gives me the .php
> file
> > like I want.  Because of this, it may not be possible to cleanly do what I
> > want, so if not, I'll just give up on the text-only idea.  (It could also
> be
> > implemented as a parameter passed to the PHP file through the URL, but that
> > wouldn't be as automatic.  If it's not a convenient side-effect, I don't
> really
> > care, because, again, no-one will probably only Accept text/plain anyways.)
> I don't know of any browser that understands text/plain and not text/html,
> so this is probably a silly idea.

Yeah, it is silly, but it's convenient to have the source files sitting in the
DocumentRoot, which is also logically where they belong.

> But if you really want to do this, there are some notes which explain the
> basic solution here:
> (Essentially, you need to use AddHandler rather than AddType to activate
> your php handler, and then use AddType to designate the php script as
> text/html.)

This worked great! Thanks.

> But then you are going to run into the problem that most browsers don't
> express a preference for text/html over text/plain anyway, so the
> text/plain might end up getting served because it is smaller.  You could,
> perhaps, use server-side quality values to fix this, but I don't really
> know the details.

  I think I fixed this because .php comes alphabetically before .txt, and
according to that page: "One important consideration here is that Internet
Explorer (under certain conditions) may send an Accept header of
*/*...Fortunately, when faced with a totally ambiguous choice, Apache’s
selection algorithm uses the alphabetically-first filename that satisfies the
conditions. By choosing file extensions carefully, you can specify the default
type to be used."  I think this also means that if the browser requested for
text/plain and text/html of equal priority, the .php will get served.  At least
it did for two browsers I tested on, one being IE.
  File extensions are, IMHO, a sort of dirty hack anyways, at least in the
context of web servers.  (I'm not trying to troll here though, I'm just
pedantic as mentioned before, so ignore me if you have reason to disagree.)
The user (or client, or webpage linking to another) shouldn't care about what
format the content gets served in.  I'd guess the reason IE sends Accept */* is
because it expects a .html or whatever to be tacked on the end of the URI it's
requesting, thus letting the server know what format to give.  This is bad
design as it works around the existence of the HTTP Accept header.
  Anyways, thanks for this link -- it works good, I'll just keep an eye out for
the caveats described.

This message was sent using IMP, the Internet Messaging Program.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message