问题
I want to redirect
www.domain.com/images/Apple.jpg
to
www.domain.com/Apple.html
Here is the Live working example, This is what i exactly want
http://more-sky.com/data/out/2/IMG_21306.jpg
How it redirect to its parent page i.e (http://more-sky.com/WDF-21306.html)
回答1:
Assuming you have mod_rewrite enabled in your Apache:
RewriteEngine On
RewriteBase /
RewriteRule ^images/([^\.]+)\.(jpe?g|png) /$1.html [QSA,L]
Edit: 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.
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>
This is not an optimal solution for a large number of images, but it seemed to fit OP's case.
来源:https://stackoverflow.com/questions/41344444/htaccess-how-to-redirect-any-jpg-page-to-its-attachment-page-html