.htaccess,如何将任何.jpg页面重定向到其附件页面(HTML)

编程入门 行业动态 更新时间:2024-10-26 12:33:43
本文介绍了.htaccess,如何将任何.jpg页面重定向到其附件页面(HTML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要重定向

www.domain/images/Apple.jpg

www.domain/images/Apple.jpg

to

www .domain / Apple.html

www.domain/Apple.html

这是Live工作示例,这正是我真正想要的 more-sky/data/out/2/IMG_21306 .jpg

Here is the Live working example, This is what i exactly want more-sky/data/out/2/IMG_21306.jpg

如何重定向到其父页面,即( more-sky/WDF-21306.html )

How it redirect to its parent page i.e (more-sky/WDF-21306.html)

推荐答案

假设您在Apache中启用了 mod_rewrite :

Assuming you have mod_rewrite enabled in your Apache:

RewriteEngine On RewriteBase / RewriteRule ^images/([^\.]+)\.(jpe?g|png) /$1.html [QSA,L]

编辑:如Wh1T3h4Ck5, QSA (查询字符串追加)标志w可能是可选的, L ( Last )也将取决于上下文和其他规则。请阅读有关 RewriteRule标志的信息。

as noticed by Wh1T3h4Ck5, QSA (Query String Append) flag would be optional, as well as L (Last) would depend on the context and other rules present. Please, read about RewriteRule flags for more information.

要澄清一下:此解决方案假定已经有图像名称的HTML文档存在。

To clarify: this solution assumes that an HTML document with the name of the image already exists. Something like:

<html> <head> <title>Apple</title> </head> <body> <img src="images/Apple.jpg" alt="Apple"> </body> </html>

对于大量图像而言,这不是最佳解决方案,但似乎适合OP的情况。

This is not an optimal solution for a large number of images, but it seemed to fit OP's case.

更多推荐

.htaccess,如何将任何.jpg页面重定向到其附件页面(HTML)

本文发布于:2023-11-01 23:31:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   如何将   重定向   附件   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!