如何配置我的 .htaccess 文件,以便对 myurl.com/imageX.bmp(其中 X 是某个整数)的查询都提供相同的图像?

发布于 2024-10-05 18:25:05 字数 136 浏览 0 评论 0原文

我希望能够使用唯一的图像名称(出于跟踪目的)接受大量图像请求,但我不想全部上传。如何配置我的 .htaccess 文件,以便对 imageX.bmp(image1.bmp image 12.bmp image5438.bmp 等)的所有请求都返回相同的图像?

I want to be able to take a large number of requests for an image using unique image names (for the purposes of tracking) however I don't want to upload them all. How can I configure my .htaccess file so that all requests for imageX.bmp (image1.bmp image 12.bmp image5438.bmp etc) all return the same image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

烟火散人牵绊 2024-10-12 18:25:05

使用 mod_rewrite 非常简单:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^path/to/the/images/image([0-9]+)\.bmp$ [NC]
RewriteRule (.*) /path/to/the/final/image.bmp

这几乎可以完成您想要的操作,将 image.bmp 的内容提供给任何 imageX.bmp 请求。如果您想深入了解 mod_rewrite,请此处这是一个不错的入门教程。

但是,正如 Goran 所建议的,向 URI 附加一个参数会更简单,而且可靠性也不会降低多少。

It's pretty easy with mod_rewrite:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^path/to/the/images/image([0-9]+)\.bmp$ [NC]
RewriteRule (.*) /path/to/the/final/image.bmp

This should pretty much do the thing you want, serve the content of the image.bmp to any imageX.bmp request. If you'd like to dwelve deeper into mod_rewrite, here's a decent tutorial to get you started.

But, as Goran suggested, appending a parameter to the URI would be simpler, and not much less reliable.

披肩女神 2024-10-12 18:25:05

我知道这并不完全是您问题的答案,但这就是我的想法(假设您使用的是基于 Unix 的操作系统)。

如果您为所有文件名创建文件系统链接,则无需 .htaccess 即可执行此操作。

例如,您将有一个 image.bmp,并链接 image1.bmp、image2.bmp .. ets 指向 image.bmp。

您可以使用以下命令创建链接:

ln -s image.bmp image1.bmp
ln -s image.bmp image2.bmp 

... 等等。

或者使用如下所示的 bash 脚本:

 #!/bin/bash
for x in {1..50000}
do
ln -s image.bmp image$x.bmp
done

这样,您只需一个文件即可满足所有请求。

但是,可能有更好的方法来解决您的问题!

只需将 GET 参数添加到您的请求中,如下所示:

http://domain.foo。 com/path/image.bmp?number=12334

然后,让一个 Web 应用程序标记所有请求及其编号。或者将所有请求记录在 apache 日志中并稍后解析出来。

希望这些确实有帮助!

I know this isn't exactly an answer to your question, but this is what I've come up with (assuming you are using a Unix based OS).

You can do this without .htaccess if you create filesystem links for all the filenames.

E.g. you would have one image.bmp, and links image1.bmp, image2.bmp .. ets pointing to image.bmp.

You can create links with:

ln -s image.bmp image1.bmp
ln -s image.bmp image2.bmp 

... etc.

Or with a bash script like this one:

 #!/bin/bash
for x in {1..50000}
do
ln -s image.bmp image$x.bmp
done

This way, you would have just one file served to all requests.

But, there may be an even better way to solve your problem!

Simply add a GET parameter to your request like this:

http://domain.foo.com/path/image.bmp?number=12334

Then, have a web app marking all requests and their numbers. Or have all requests logged in apache log and parse it out later.

Hope any of these actually help!

身边 2024-10-12 18:25:05

+1 使用 image.bmp?number=12345 而不是 image12345.bmp

+1 for using image.bmp?number=12345 instead of image12345.bmp

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