{"id":1695,"date":"2008-07-11T18:59:38","date_gmt":"2008-07-11T10:59:38","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/"},"modified":"2017-10-31T20:53:39","modified_gmt":"2017-10-31T12:53:39","slug":"smarter-way-to-prevent-image-hotlinking-with-htaccess","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/","title":{"rendered":"Smarter Way To Prevent Image Hotlinking with .htaccess"},"content":{"rendered":"<p>Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call <strong>image hotlinking<\/strong>. It is bad, as it not only stealing our images, it also take advantage of our bandwidths. Because it\u2019s called directly from our server, every time the images are loaded on their webside it cost us bandwidths. Controlling via <a href=\"http:\/\/httpd.apache.org\/docs\/1.3\/howto\/htaccess.html\">.htaccess<\/a> is one of the most efficient way to prevent image hotlinking.<\/p>\n<p>And by smarter way, we mean giving the webmaster more control on the .htaccess in terms of:<\/p>\n<ul>\n<li>what sites to block<\/li>\n<li>what sites to allow<\/li>\n<li>allow\/deny blank referrers<\/li>\n<li>display custom images detecting image hotlinking<\/li>\n<li>files to protect<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h2>Step 1 \u2013 Create .htaccess<\/h2>\n<p>If you\u2019re currently not using any .htaccess in your web account you should be creating one. Open up notepad, save it as .<strong>htaccess<\/strong> without any extension behind. For those who already have an existing .htaccess file, download it to your local computer as we\u2019ll be doing some editing in Step 2.<\/p>\n<h2>Step 2 \u2013 .htaccess hotlinking code<\/h2>\n<p>Paste this following code into your .htaccess.<\/p>\n<pre>\r\nRewriteEngine on\r\nRewriteCond %{HTTP_REFERER} !^$\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourdomain.com [NC]\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourdomain2.com [NC]\r\nRewriteRule \\.(jpg|jpeg|png|gif)$ http:\/\/hpmouse.googlepages.com\/hotlink.gif [NC,R,L]\r\n<\/pre>\n<h2>Explanation<\/h2>\n<p><strong>Line 2 \u2013 Allow blank referrers (recommended). <\/strong><\/p>\n<pre>\r\n\u00a0\r\nRewriteCond %{HTTP_REFERER} !^$\r\n<\/pre>\n<p>Some users surf under firewall and thus they are not providing any referrers information. Disallowing blank referrers will means blocking them from accessing these images. However if you want to block blank referrers, just delete line 2.<\/p>\n<p><strong>Line 3, Line 4 \u2013 Sites allowed to link your images.<\/strong><\/p>\n<pre>\r\n\u00a0\r\n\u00a0\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourdomain.com [NC]\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourdomain2.com [NC]\r\n\u00a0\r\n<\/pre>\n<p>By default all sites are blocked from hotlinking. Only those specified by you are allowed to do so.<\/p>\n<p><strong>Line 5 \u2013 File format to block, custom blocking images.<\/strong><\/p>\n<pre>\r\n\u00a0\r\n\u00a0\r\n\u00a0\r\n\u00a0\r\nRewriteRule \\.(jpg|jpeg|png|gif)$ http:\/\/hpmouse.googlepages.com\/hotlink.gif [NC,R,L]\r\n<\/pre>\n<p>In between the () are images you intended to block from hotlinking. To add more seperate them with\u201d|\u201d<\/p>\n<p>Change \u2018<em>http:\/\/hpmouse.googlepages.com\/hotlink.gif<\/em>\u2018 to a image you\u2019ve set, and whenever image hotlinking is detected, this image will show up. <strong>Just make sure where this image is not hotlink protected or your server can go into an endless loop<\/strong>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image hotlinking. It is bad, as it not only stealing our images, it also take advantage of our bandwidths. Because it\u2019s called directly from our server, every time the images are&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3398],"tags":[952],"topic":[4521],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Smarter Way To Prevent Image Hotlinking with .htaccess - Hongkiat<\/title>\n<meta name=\"description\" content=\"Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Smarter Way To Prevent Image Hotlinking with .htaccess\" \/>\n<meta property=\"og:description\" content=\"Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2008-07-11T10:59:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-31T12:53:39+00:00\" \/>\n<meta name=\"author\" content=\"Hongkiat Lim\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hongkiat Lim\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/\"},\"author\":{\"name\":\"Hongkiat Lim\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e3613a3bf757e4f67770f0b7a339edd0\"},\"headline\":\"Smarter Way To Prevent Image Hotlinking with .htaccess\",\"datePublished\":\"2008-07-11T10:59:38+00:00\",\"dateModified\":\"2017-10-31T12:53:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/\"},\"wordCount\":327,\"commentCount\":22,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"htaccess\"],\"articleSection\":[\"Internet\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/\",\"name\":\"Smarter Way To Prevent Image Hotlinking with .htaccess - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2008-07-11T10:59:38+00:00\",\"dateModified\":\"2017-10-31T12:53:39+00:00\",\"description\":\"Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/smarter-way-to-prevent-image-hotlinking-with-htaccess\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Smarter Way To Prevent Image Hotlinking with .htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e3613a3bf757e4f67770f0b7a339edd0\",\"name\":\"Hongkiat Lim\",\"description\":\"Founder and Editor in Chief of Hongkiat.com. Hongkiat is also a designer, developer, entrepreneur, and an active investor in the US stock market.\",\"sameAs\":[\"http:\\\/\\\/www.hongkiat.com\\\/blog\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/hongkiat\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Smarter Way To Prevent Image Hotlinking with .htaccess - Hongkiat","description":"Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/","og_locale":"en_US","og_type":"article","og_title":"Smarter Way To Prevent Image Hotlinking with .htaccess","og_description":"Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image","og_url":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2008-07-11T10:59:38+00:00","article_modified_time":"2017-10-31T12:53:39+00:00","author":"Hongkiat Lim","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Hongkiat Lim","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/"},"author":{"name":"Hongkiat Lim","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e3613a3bf757e4f67770f0b7a339edd0"},"headline":"Smarter Way To Prevent Image Hotlinking with .htaccess","datePublished":"2008-07-11T10:59:38+00:00","dateModified":"2017-10-31T12:53:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/"},"wordCount":327,"commentCount":22,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["htaccess"],"articleSection":["Internet"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/","url":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/","name":"Smarter Way To Prevent Image Hotlinking with .htaccess - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2008-07-11T10:59:38+00:00","dateModified":"2017-10-31T12:53:39+00:00","description":"Have you noticed someone stealing your images, directly taking the URL and display on their websites without your permission? This is what we call image","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Smarter Way To Prevent Image Hotlinking with .htaccess"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e3613a3bf757e4f67770f0b7a339edd0","name":"Hongkiat Lim","description":"Founder and Editor in Chief of Hongkiat.com. Hongkiat is also a designer, developer, entrepreneur, and an active investor in the US stock market.","sameAs":["http:\/\/www.hongkiat.com\/blog"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/hongkiat\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-rl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/1695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=1695"}],"version-history":[{"count":9,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/1695\/revisions"}],"predecessor-version":[{"id":12987,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/1695\/revisions\/12987"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=1695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=1695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=1695"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=1695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}