mod_rewrite 与符号链接:浏览器不会被愚弄
我的服务器上有一个文件 foo.bar.1 ,当我尝试从浏览器(firefox)访问它时,我会收到一个弹出窗口,显示“您已选择打开 foo.bar.1,它是一个:1 文件.. Firefox 应该如何处理这个文件...”。 如果我创建一个指向它的符号链接 foo.dat,我就可以很好地访问它; 内容按照我的预期显示在浏览器中。
我的问题是我不想为所有这些文件创建符号链接,我想使用 mod_rewrite 规则,例如
RewriteRule ^([^/]+)\.dat$ $1.bar.1
但这不像符号链接。 它给出了相同的弹出窗口(尽管奇怪的是,它现在说“您已选择打开 foo.dat,它是一个:DAT 文件...”。
我该如何执行重写规则,以便欺骗浏览器将其视为一个普通的 .dat 文件,由符号链接完成?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您安装了 mod_mime,那么您可以执行以下操作:
未测试,但它应该显示文件而不是下载
请参阅 http://httpd.apache.org/docs/2.0/mod/mod_mime.html#addtype 用于 AddType 文档
If you have mod_mime installed, then you can do:
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
查看
RewriteRule
指令的[T]
参数:http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
当您创建符号链接时,Apache 认为它正在提供
.dat
文件,而当您使用 mod_rewrite 时,Apache 仍然认为它提供的是.1
文件。 这出现在提供给浏览器的 Content-type 标头中。Look in to the
[T]
argument to theRewriteRule
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.