.htaccess图像链接重定向 [英] .htaccess redirection for image link

查看:76
本文介绍了.htaccess图像链接重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在 .htaccess 文件中设置重定向,以便如果另一个网站直接链接到我网站上的图像,在浏览器窗口中单独打开的图片中,将显示托管该图片的页面。

I would like to know if it is possible to set up a redirect in the .htaccess file so that if another website directly links to an image on my site, instead of the image opening in a browser window on its own, the page that the image is hosted on is displayed.

此页面与图片同名,即另一个网站链接到的图片是

This page has the same name as the image i.e. if the image the other site is linking to is

案例1

www.example.com/subdirABC/gallery/image.jpg
**to**
www.example.com/subdirABC/
**or**
www.example.com/subdirABC/index.php

案例2

www.example.com/subdirXYZ/gallery/image.jpg
**to**
www.example.com/subdirXYZ/
**or**
www.example.com/subdirXYZ/index.php


推荐答案

对我有用

RewriteBase /
Options +FollowSymLinks
RewriteCond %{HTTP_REFERER} !^https://example.com
RewriteRule ^(.*)/gallery/(.*.jpg) /$1/ [L,R=301]

这篇关于.htaccess图像链接重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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