views:

319

answers:

2

I have a file foo.bar.1 on my server and when I try to access it from a browser (firefox) I get a popup that says "You have chosen to open foo.bar.1 which is a: 1 file ... What should Firefox do with this file...". If I create a symlink to it, foo.dat, I can access it just fine; the contents display in the browser as I expect.

My problem is that I don't want to create symlinks for all these files, I want to use a mod_rewrite rule, like

RewriteRule ^([^/]+)\.dat$ $1.bar.1

But that doesn't act like the symlink. It gives the same popup (though, strangely, it now says "You have chosen to open foo.dat which is a: DAT file ...".

How can I do the rewrite rule such that the browser is tricked into treating it like a normal .dat file, as is accomplished by the symlink?

+2  A: 

If you have mod_mime installed, then you can do:

AddType text/plain .1

Not tested, but it should display the file instead of download

See http://httpd.apache.org/docs/2.0/mod/mod_mime.html#addtype for AddType documentation

MartinodF
+1  A: 

Look in to the [T] argument to the RewriteRule directive:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

When you make the symlink, Apache thinks it's serving a .dat file, whereas when you use mod_rewrite, Apache still thinks it's serving a .1 file. This turns up in the Content-type header served to the browser.

Jim Puls
Thanks! This seems like it should work but I added [T=text/plain] to no effect. No I'm even more confused...
dreeves