图像重写
这可能更像是一个检查而不是一个问题,但以下是正确的:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不会起作用,因为
(.*)
是贪婪的,会匹配尽可能多的字符,甚至是下划线。像这样(分隔符之间不允许下划线):或这样(不贪婪的匹配):
或两者的组合应该可以工作。 (取决于每个块中允许的字符)
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):or this (ungreedy matching):
or a combination of both should work. (Depending of what chars are allowed within each block)