Jump to content

This Rewrite rule blocks images from displaying


mr_bob
 Share

Recommended Posts

Hi all,

Following advice of one member here I managed to write following rules. It's needed to block direct access, but allow files to be read by html code like this:

RewriteEngine On 
RewriteCond %{HTTP_REFERER} !^(www\.)?domain\.com [NC]
RewriteCond %{HTTP_REFERER} !^(www\.)?domain\.com.*$ [NC]
RewriteRule \.(gif|jpg|mp3|ogg|)$ - [F]

It's needed for www.domain.com and https://domain.com.

Problem is that page.html doesn't display images and mp3 files after that. [L] at the end allows them display but direct access too.

What could be wrong here?

Link to comment
Share on other sites

If you view a page at https://www.domain.com/page.html and it tries to show an image from https://www.domain.com/image/img.jpeg, what do you think the referrer string will be?

Also, you cannot rely on the referrer string even being present. You should only block access if there is one.

Link to comment
Share on other sites

Just now, requinix said:

If you view a page at https://www.domain.com/page.html and it tries to show an image from https://www.domain.com/image/img.jpeg, what do you think the referrer string will be?

Also, you cannot rely on the referrer string even being present. You should only block access if there is one.

I guess we're missing jpeg here which should be added to the list. Maybe I should declare /image/ directory? Regular expressions are hammering me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.