Apache.htaccess hotlinking redirect

I am trying to create a redirect when someone accesses images in the same directory on my site. If someone refers to an image, I want to redirect them to the corresponding image (same file name) to another directory.

If someone has hotlinks:

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

I want it to redirect to:

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

Thoughts?

+3
source share
1 answer
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]

, , /Embedded, jpg/gif/png, URL- //

[R=302] .

+8

Source: https://habr.com/ru/post/1712578/


All Articles