Learning_to_program
Learning_to_program

Reputation: 27

Apache custom 404 page: relative links break in sub directories

The Apache version is 2.4. In httpd.conf, there is a virtual server with a custom 404 page:

<VirtualHost *:80>
     ServerAdmin **
     DocumentRoot /var/www/html/**
     ServerName www.**
     ServerAlias **
     ErrorDocument 404 /404.html
</VirtualHost>

The 404.html document is on the root directory of the website, and in it, there are relative links and images from the sub directory "imgaes" (<img src="images/some_img.jpg" /> - relative image links).

If the request for the non existent page is done in the root dir, like www.website.com/not_found, the images on the 404.html display well, but if the non-existent page was requested in a sub directory, like www.website.com/sub_sir/not_found, all images and links get broken.

Is there a way to tell Apache to redirect to the 404 page as if it is on root dir, and not display it like it is to the current requested dir?

Upvotes: 0

Views: 382

Answers (1)

miew
miew

Reputation: 26

try to make your links relative to your public html root, in your case <img src="/images/some_img.jpg" /> hope it works :)

Upvotes: 1

Related Questions