You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Michał Pałka <mi...@poczta.fm> on 2006/04/29 11:26:43 UTC

[users@httpd] [mod_rewrite] Content-type doesn't change, logs say otherwise

List,

I've run across a strange problem. I want to serve .html files with
application/xhtml+xml for selected browsers and as text/html for others.
Therefore, I've included these rules in my .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteRule \.html$|/$ - "[T=application/xhtml+xml;charset=utf-8]"

The rule matches urls ending with / as well because directory urls
mapped to index.html were not covered otherwise. However, the dir/ urls
are still unconditionally served as text/html even though the rewrite
log says something else:
195.150.76.4 - - [28/Apr/2006:23:18:01 +0200] [sphinx.tcs.ii.uj.edu.pl/sid#81883d8][rid#8200d00/initial] (3) [per-dir /home/michal/public_html/] strip per-dir prefix: /home/michal/public_html/SZPI/ -> SZPI/
195.150.76.4 - - [28/Apr/2006:23:18:01 +0200] [sphinx.tcs.ii.uj.edu.pl/sid#81883d8][rid#8200d00/initial] (3) [per-dir /home/michal/public_html/] applying pattern '\.html$|/$' to uri 'SZPI/'
195.150.76.4 - - [28/Apr/2006:23:18:01 +0200] [sphinx.tcs.ii.uj.edu.pl/sid#81883d8][rid#8200d00/initial] (4) RewriteCond: input='text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' pattern='application/xhtml\+xml' => matched
195.150.76.4 - - [28/Apr/2006:23:18:01 +0200] [sphinx.tcs.ii.uj.edu.pl/sid#81883d8][rid#8200d00/initial] (4) RewriteCond: input='text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' pattern='!application/xhtml\+xml\s*;\s*q=0' => matched
195.150.76.4 - - [28/Apr/2006:23:18:01 +0200] [sphinx.tcs.ii.uj.edu.pl/sid#81883d8][rid#8200d00/initial] (1) [per-dir /home/michal/public_html/] force /home/michal/public_html/SZPI/ to have MIME-type 'application/xhtml+xml;charset=utf-8'
195.150.76.4 - - [28/Apr/2006:23:18:01 +0200] [sphinx.tcs.ii.uj.edu.pl/sid#81883d8][rid#8200d00/initial] (1) [per-dir /home/michal/public_html/] pass through /home/michal/public_html/SZPI/

On the other hand, dir/index.html is served the right way while giving
the same output in the log.

I guess that I'm missing here some strange interaction between
mod_rewrite and DirectoryIndex.

I'm using Apache 2.0.55-4 from Debian.

Any help appreciated.

Thanks,
Michal



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] [mod_rewrite] Content-type doesn't change, logs say otherwise

Posted by Michał Pałka <mi...@poczta.fm>.
On Sun, 2006-04-30 at 14:50 -0400, Joshua Slive wrote:
> On 4/29/06, Michał Pałka <mi...@poczta.fm> wrote:
> 
> > RewriteEngine on
> > RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
> > RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
> > RewriteRule \.html$|/$ - "[T=application/xhtml+xml;charset=utf-8]"
> 
> > I guess that I'm missing here some strange interaction between
> > mod_rewrite and DirectoryIndex.
> 
> Probably.  I bet you can get around the problem by letting mod_rewrite
> do the processing normally done by mod_dir.  For example:
> RewriteRule (.*)/$ $1/index.html "[T=application/xhtml+xml;charset=utf-8]"
> 
> Joshua.

Thanks Joshua,

This works indeed. One other thing that I had to add was RewriteBase
since apache was looking for the files in DocumentRoot otherwise.

Michal


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] [mod_rewrite] Content-type doesn't change, logs say otherwise

Posted by Joshua Slive <jo...@slive.ca>.
On 4/29/06, Michał Pałka <mi...@poczta.fm> wrote:

> RewriteEngine on
> RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
> RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
> RewriteRule \.html$|/$ - "[T=application/xhtml+xml;charset=utf-8]"

> I guess that I'm missing here some strange interaction between
> mod_rewrite and DirectoryIndex.

Probably.  I bet you can get around the problem by letting mod_rewrite
do the processing normally done by mod_dir.  For example:
RewriteRule (.*)/$ $1/index.html "[T=application/xhtml+xml;charset=utf-8]"

Joshua.