Jump to content

Recommended Posts

I have a htaccess file which causes redirects to a custom 404.php page when files can't be found. The htaccess file contains the following code:

php_value upload_max_filesize 50M
php_value post_max_size 50M
php_value max_execution_time 6000
php_value max_input_time 6000
php_value memory_limit 128M
php_flag magic_quotes_gpc off
php_flag display_errors on
ErrorDocument 404 /404.php

 

So, pages such as mydomain.com/filethatcantbelocated.php redirect to the 404.php page without problem.

 

However, pages like mydomain.com/somedirectory/filethatcantbelocated.php don't result in the 404.php page being displayed properly. Css files in the header include are not being referenced properly or something. At the top of the 404.php page, there's this code:

<?php
session_start();
include("lib/inc/inc.header.php");
?>

 

Can someone please tell me what I need to do - either to the htaccess file or to the 404.php page - in order to fix this problem?

 

Your help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/242926-htaccess-and-custom-404-page/
Share on other sites

  • 2 weeks later...

You need to edit inc.header.php and change the src paths for your css /images, they need to be paths relative to root not relative to the current file (they should either be full paths beginning with your domain or they should begin with a forward slash. When the 404 document is displayed it appears to the user that it's location is the URI they requested. Therefore if your css path is 'styles/base.css', a request for /somefolder/somefile.html will make the clients browser attempt to download yoursite.com/somefolder/images/base.css, if you simply changed the path to be '/styles/base.css' it would always request yoursite.com/styles/base.css.

 

It can get a little confusing working out the difference between using server relative paths and client relative paths.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.