Apache .htaccess hotlinking redirect

家住魔仙堡 提交于 2020-01-21 05:40:06

问题


I am trying to create a redirection when someone hotlinks images in one directory on my site. If someone hotlinks an image, I want to redirect them to a corresponding image (same file name) in a different directory.

If someone hotlinks:

www.mydomaoin.com/PlayImages/Basic/Embedded/{ImageName.gif}

I want it to redirect to:

www.mydomaoin.com/PlayImages/Basic/Shared/{ImageName.gif}

Thoughts?


回答1:


RewriteEngine on

#redirect image hotlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/?.*$ [NC]
RewriteCond %{REQUEST_URI} (.*)/Embedded/(.*jpg|.*gif|.*png)$ [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}/%1/Shared/%2 [R=302,L]

If the referrer is not blank, and the referrer is not equal to your own domain, and the request is for a resource in the /Embedded folder ending in jpg/gif/png, then rewrite the url to replace /Embedded with /Shared

You may want to change the [R=302] to a different code to suit your needs.



来源:https://stackoverflow.com/questions/1126552/apache-htaccess-hotlinking-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!