How to implement 404, 403 redirect URL's using .htaccess properly?

I’ve created a website which has directory structure as follows :

root /
   imgs /
     branding/
     helpers/
  styles/
     some_style.css
  index.php
  .htaccess
  error.html

Here, as you can see I’ve placed my error page in the root folder. My .htaccess file content is as follows :

# Used to hide the file extensions
Options +MultiViews

# Returns random URL typed in the address bar to the error page of feedback
ErrorDocument 403 /feedback/error.html
ErrorDocument 404 /feedback/error.html

Whenever I try to access a random URL with my webpage let’s say : www.some-domain.com/non-existed-url
It works. But when I try to access something like this : “www.some-domain.com/imgs/asdasasd” where imgs folder exists in the root folder and as I’ve prevented directory listing, it works fine.

The only issue is that when accessed like some-domain.com/imgs/random-url the CSS and imgs won’t show up which are used in error.html file.

What should I do for this? Should I copy 'n paste error.html in each directory and create .htaccess in that directory and specify the URL?

To access images and CSS I’ve used href attribute something like this : ./styles/error.css
BUT
when I get the error and add another . in the href attribute it, works!

I’m not getting the logic, what’s happening actually, and how it works?

Error images :

Working correctly :

Error :

Thanks

Do you have relative addresses in error.html?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.