Apache .htaccess hotlinking redirect

前端 未结 1 1867
野性不改
野性不改 2021-01-06 14:25

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

相关标签:
1条回答
  • 2021-01-06 14:40
    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.

    0 讨论(0)
提交回复
热议问题