Home > apache 2.2 > Make MultiViews work even if the requested file does exist

Make MultiViews work even if the requested file does exist

May 12Hits:0

From the Apache 2 docs:

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files...

Is there any way to make MultiViews do its magic even if the requested file does exist? For example I might have these files:

  • foo.html
  • foo.html.gz

When /foo.html is requested, I want to return foo.html.gz if the Accept-Encoding: gzip header is sent.

MultiViews can do this fine, but you have to either request just /foo or rename foo.html to foo.html.en (which is hackish, and doesn't work if you request from a non-English browser).


This will make it load the .gz file if gzip compression is accepted. Otherwise it'll skip this rule and just load the normal html file.

Note: You must have the mod_rewrite module installed to use this.

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule ^(.*).html$ $1.html.gz [NC,L,QSA]

Related Articles

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.826 s.