3

I'm trying to create HTACCESS Hotlink Protection on my site but I'd like all Google top level domains (.com., .co.in, .co.uk, etc) to be able to access my files, so that visitors to the Google AMP version of my pages can view linked images and resources.

I tried the following in my htaccess but it's blocking Google AMP users

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !.*google.*  [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?patchworkoftips.com [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?feeds.feedburner.com [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?feeds2.feedburner.com [NC]

RewriteRule \.(jpg|jpeg|gif|png|bmp|iso|zip|mp4|exe|xlsx|img|rar|apk|bar|7z|ipd)$ https://i.ibb.co/2hcQgZw/stop-hotlinking-images.jpg [NC,R,L]

For example, the URL for my Google AMP page starts with www.google.com.ng/amp/s/ and when users of such pages click to download a file they get an error image.

Anybody accessing the site directly from the main domain www.patchworkoftips.com can easily download the file.

I added RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com.ng [NC] but it doesn't seem to work either for some reason

I saw someone mention RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google\.*$/.*$but someone replied that this would give access to sites like "googlefake.com", "google123.es"

So the question here is how can I enable file download access for users landing on the Google AMP pages on my site and what would be the best way to achieve this for all google TLDs without clogging the htaccess file.

4
  • 1
    Note: Part of this process will be to allow the Google Images bot to bypass hotlinking restrictions too. More info: support.google.com/webmasters/answer/80553 Commented Dec 11, 2018 at 1:26
  • "but it's not working at all" - How are you testing this? In what way is it "not working"? Please include your complete .htaccess code. The code you've posted is simply a "condition" - which doesn't do anything by itself.
    – MrWhite
    Commented Dec 11, 2018 at 2:15
  • @MrWhite Sorry about that sir. I'm new to thing. I've edited the post to add more information and I also included the complete .htaccess code Commented Dec 11, 2018 at 6:42
  • 1
    @MaximillianLaumeister thanks for the heads up sir. I actually made a mistake in my first post which I've edited. My problem is getting file downloads on my pages hosted by Google AMP to work for users. Please see edited first post again sir. Thanks Commented Dec 11, 2018 at 6:44

1 Answer 1

2

Thanks guys. I've got it working by adding this rule RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?www-patchworkoftips-com.cdn.ampproject.org [NC].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.