skip to Main Content

I have folder with images in root directory and I need deny to access that images from URL.

I have .htaccess in this folder

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http(s?)://(www.)?localhost.*$ [NC] 
RewriteRule .(gif|jpg|jpeg|png)$ - [F]

This works perfect and if try to access image via URL, it shows error

Forbidden

You don’t have permission to access ..

But I want instead, redirect to my custom error page (which is /error controller in my case).

What is correct .htaccess syntax for this?

2

Answers


  1. specify

       ErrorDocument 403 /error
    

    after line RewriteEngine on

    so it will be like this :

    RewriteEngine on 
    ErrorDocument 403 /error
    RewriteCond %{HTTP_REFERER} !^http(s?)://(www.)?localhost.*$ [NC] 
    RewriteRule .(gif|jpg|jpeg|png)$ - [F]
    
    Login or Signup to reply.
  2. It should be something like this:

    ErrorDocument 403 /errors/forbid.html
    

    Have a look at this link http://www.javascriptkit.com/howto/htaccess2.shtml

    I’m not sure that it would work with a route, maybe you have to specify a document.
    I’d try it though.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search