所有网站图片上的 Mod_rewrite
我正在设计一个图像存储库。我想将文件名与图像 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能需要很长时间才能遇到实际的性能问题,但是通过 PHP 运行每个资源请求(每个进程,特别是在连接到数据库或执行其他复杂操作时,每个进程都会占用大量内存在我看来,request)在架构上是一个坏主意。
我建议在文件系统中将
12543
翻译为car
,然后对其进行(更便宜的)URL 重写:替代想法:像 Stack Overflow 那样这样做怎么样? 。将 jpeg 命名为
12543.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
tocar
in the file system already, and then doing a (cheaper) URL rewrite for it:Alternative idea: How about doing it like Stack Overflow. Name the jpeg
12543.jpg
and do(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 the12543
and the.jpg
).