Ben Love on 12 Apr 2010 19:33:06 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] Apache Content Negotiation


My website has the following files:

/sitemap.php
  a script to generate a nice text/html version of my sitemap.
/sitemap.xml
  an application/xml representation of my sitemap in XML Sitemap Schema.
/sitemap.xml.gz
  simply a gzip'd version of the sitemap.xml.

Now this is what I want for URLs:

/sitemap
  should return the text/html version, unless /only/ application/xml is
  an acceptable content-type, in which case then it should return the
  sitemap.xml.gz if gzip is an acceptable content-encoding, otherwise
  the sitemap.xml.

/sitemap.xml
  should return the sitemap.xml.gz if gzip is an acceptable
  content-encoding, otherwise the sitemap.xml.

/sitemap.xml.gz
  should return the sitemap.xml.gz always.

/sitemap.php
  should return the text/html version always.

But here's where I start to run into problems.  /sitemap always returns
the /sitemap.xml file, so I created a type-map file called /sitemap.var.
It looks like this:

URI: sitemap.php
Content-type: text/html; qs=1.0

URI: sitemap.xml.gz
Content-type: application/xml; qs=0.001
Content-encoding: x-gzip

URI: sitemap.xml
Content-type: application/xml; qs=0.001

This causes /sitemap to return the text/html version like I want.
However, the /sitemap.xml URL just returns the /sitemap.xml every time.
So I create a /sitemap.xml.var.  It looks like this:

URI: sitemap.xml.gz
Content-type: application/xml; qs=1.0
Content-encoding: x-gzip

URI: sitemap.xml
Content-type: application/xml; qs=0.001

But, now /sitemap returns the /sitemap.xml file every time again!

Interestingly enough, all is not lost.  It turns out that these URLs
behave the way I would like:

/sitemap.var
  returns the text/html version unless application/xml is specifically
  requested, in which case it returns the sitemap.xml.gz file if gzip is
  an acceptable content-encoding, otherwise it returns the sitemap.xml
  file!

/sitemap.xml.var
  returns the sitemap.xml.gz file if gzip is an acceptable
  content-encoding, otherwise it returns the sitemap.xml file!

In other words, the .var files do /exactly/ what I want.  (Well,
almost.)  There is still one slight problem.  If one requests the
/sitemap.xml.var but does not specify an accept-encoding at all, the
/sitemap.xml.gz file is returned.  However, if one specifies any set of
accept-encodings at all, except gzip, the proper /sitemap.xml file is
returned.

So the question is, what can I possibly do to get the intended URLs
behave properly?  It seems like Apache has some sort of internal
precedence for extensions that is causing it to get in the way of
processing the .var type-map files.

Ben

-- 
Ben Love
http://www.kylimar.com/

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug