mod_rewrite 与符号链接:浏览器不会被愚弄

发布于 2024-07-21 17:35:51 字数 421 浏览 5 评论 0原文

我的服务器上有一个文件 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-07-28 17:35:51

如果您安装了 mod_mime,那么您可以执行以下操作:

AddType text/plain .1

未测试,但它应该显示文件而不是下载

请参阅 http://httpd.apache.org/docs/2.0/mod/mod_mime.html#addtype 用于 AddType 文档

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

回忆躺在深渊里 2024-07-28 17:35:51

查看 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文