所有网站图片上的 Mod_rewrite

发布于 2024-09-04 07:25:46 字数 317 浏览 4 评论 0原文

我正在设计一个图像存储库。我想将文件名与图像 html 链接分开。例如:

  • 文件系统中的图像称为 images/items/12543.jpg
  • HTML 为

是否有人强烈反对我使用 PHP 重写所有图像请求,这样在检索 images/car.jpg 时,Apache 真的会回复 images/items/12543.jpg 中的内容吗?

我不知道我是否会遇到性能问题。

I'm designing an image repository. I want to uncouple the filename from the image html link. For instance:

  • image in filesystem is called images/items/12543.jpg
  • HTML is <img src="images/car.jpg" />

Does anyone strongly discourages me to rewrite all image requests using PHP so when retrieving images/car.jpg, Apache really replies content from images/items/12543.jpg?

I don't know if I may get performance problems.

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

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

发布评论

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

评论(1

听不够的曲调 2024-09-11 07:25:46

可能需要很长时间才能遇到实际的性能问题,但是通过 PHP 运行每个资源请求(每个进程,特别是在连接到数据库或执行其他复杂操作时,每个进程都会占用大量内存在我看来,request)在架构上是一个坏主意。

我建议在文件系统中将 12543 翻译为 car,然后对其进行(更便宜的)URL 重写:

* images/items/car.jpg
* <img src="images/car.jpg" />

替代想法:像 Stack Overflow 那样这样做怎么样? 。将 jpeg 命名为 12543.jpg 并执行

<img src="images/12543/car.jpg"> 

car 部分是任意的,仅用于用户和搜索引擎的享受 - 重写规则真正解析的是什么,以及用于获取图像的只有 12543.jpg)。

It may take a long time until you will get actual performance problems with this, but running each request for a resource through PHP (every process, especially when connecting to a database or doing other complex things, taking up considerable memory on each request) is a bad idea architecturally IMO.

I would recommend either translating 12543 to car in the file system already, and then doing a (cheaper) URL rewrite for it:

* images/items/car.jpg
* <img src="images/car.jpg" />

Alternative idea: How about doing it like Stack Overflow. Name the jpeg 12543.jpg and do

<img src="images/12543/car.jpg"> 

(The car part being arbitrary and there only for the user's and search engines' enjoyment - what is really parsed by the rewrite rule, and used to fetch the image, is only the 12543 and the .jpg).

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