图像重写

发布于 2024-12-28 06:49:49 字数 445 浏览 2 评论 0原文

这可能更像是一个检查而不是一个问题,但以下是正确的:

RewriteRule ^_images/(.*)_(.*)_(.*)$ /_images/$2_$3 [L]

基本上我想自动使网页使用 /_images/picture-name_ABC123_600.jpg (实际上并不存在)但实际上使用确实存在的图像 /_images/ABC123_600.jpg

我在 XAMPP 本地对其进行了检查,并且工作正常,但是我认为我最好尝试添加更多下划线,例如。 /_images/picture-name_A_B_C_1_2_3_600.jpg 我期待它能工作,但图像仍然出现 - 那么这是正常行为吗?

我也不太确定是否可以在上面的两个美元符号之间使用下划线...

任何帮助都会很棒!

This is probably more of a check than a question, but is the following correct:

RewriteRule ^_images/(.*)_(.*)_(.*)$ /_images/$2_$3 [L]

Basically I want to automatically make webpages use /_images/picture-name_ABC123_600.jpg (which doesn't really exist) but actually use the image /_images/ABC123_600.jpg that does exist.

I gave it a check locally in XAMPP, and worked, however I though that I'd better try adding more underscores eg. /_images/picture-name_A_B_C_1_2_3_600.jpg which I was expecting to work, yet the image still appeared - so is this normal behavour?

I'm also not too sure if I can use an underscore between the two dollar signs above...

Any help would be great!

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

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

发布评论

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

评论(1

四叶草在未来唯美盛开 2025-01-04 06:49:49

这不会起作用,因为 (.*) 是贪婪的,会匹配尽可能多的字符,甚至是下划线。像这样(分隔符之间不允许下划线):

RewriteRule ^_images/([^_]*)_([^_]*)_([^_]*)$ /_images/$2_$3 [L]

或这样(不贪婪的匹配):

RewriteRule ^_images/(.*?)_(.*?)_(.*?)$ /_images/$2_$3 [L]

或两者的组合应该可以工作。 (取决于每个块中允许的字符)

This will not work as the (.*) is greedy and matches as many characters as it can, even underscores. Something like this (not allowing underscore between the separators):

RewriteRule ^_images/([^_]*)_([^_]*)_([^_]*)$ /_images/$2_$3 [L]

or this (ungreedy matching):

RewriteRule ^_images/(.*?)_(.*?)_(.*?)$ /_images/$2_$3 [L]

or a combination of both should work. (Depending of what chars are allowed within each block)

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