设置图像路径的技术?

发布于 2024-09-27 12:41:55 字数 422 浏览 0 评论 0原文

示例:

<img src="/images/name.jpg" alt="" />

这就是我想要的:

<img src="name.jpg" alt="" />

在请求图像时,将找不到该图像,因为它位于“images”目录中,而不是位于 HTML 文件所在的根目录中。

有没有办法 htaccess 或任何其他技术能够识别 http 图像请求并用前缀路径 (/images/) 重写它?

例如,当 htaccess 读取扩展名(.jpg)时,它可以说类似的内容吗?

嘿 .jpg,您是一个图像,让我们在前面添加图像路径并将您发送回客户端

提前致谢!

Example:

<img src="/images/name.jpg" alt="" />

This is what I want:

<img src="name.jpg" alt="" />

Upon request for the image, the image will not be found because it is in the "images" directory and not in the root where the HTML file is.

Is there a way htaccess or any other technique will be able to recognise the http image request and rewrite it with the the path (/images/) prepended?

For example when htaccess reads the extension (.jpg) can it say something like

Hey .jpg you're an image, let's prepend the images path and send you back to the client

Thanks in advance!

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

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

发布评论

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

评论(1

萤火眠眠 2024-10-04 12:41:55

这是可能的,但不是一个好主意。通过将所有传入的图像请求重写到某个位置,您可以将服务器上可以存储图像的文件夹数量减少到一个。

更好的想法是始终使用正确的路径 - 即使是像您显示的那样的绝对路径。

This is possible, but not a good idea. By rewriting all incoming requests for images to a certain location, you will be reducing the number of possible folders in which you can store images on your server to one.

The better idea is to always use a correct path - even an absolute path like the one you are showing.

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