.htaccess,如何将任何.jpg页面重定向到其附件页面(HTML) [英] .htaccess , How to redirect any .jpg page to its attachment page (HTML)

查看:103
本文介绍了.htaccess,如何将任何.jpg页面重定向到其附件页面(HTML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向


www.domain.com/images/Apple.jpg

www.domain.com/images/Apple.jpg





to


www .domain.com / Apple.html

www.domain.com/Apple.html

这是Live工作示例,这正是我真正想要的

http://more-sky.com/data/out/2/IMG_21306 .jpg

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

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

How it redirect to its parent page i.e (http://more-sky.com/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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆