Jump to content

[Solved] Set custom 404 Error for static contents


afshin.m

Recommended Posts

Hi,i want to set a custom (and empty) 404 error for my static contents like CSS, Gif, Jpeg etc.i found this code :

<FilesMatch "\.(css|png|jpg|jpeg|gif|bmp|swf|flv)$">   ErrorDocument 404 error-404.txt</FilesMatch>

But it not worked for images that located in sub folders, it works for images that located in the root folder and where my .htaccess file located.Please help, thanks

Link to comment
Share on other sites

Can you modify httpd.conf, or another file in /etc/httpd/conf.d? If it's shared hosting, the answer is probably no.You could create a symlink (ln -s ../.htaccess) to reuse the .htaccess file from the subdirectories.

Link to comment
Share on other sites

Can you modify httpd.conf, or another file in /etc/httpd/conf.d? If it's shared hosting, the answer is probably no.You could create a symlink (ln -s ../.htaccess) to reuse the .htaccess file from the subdirectories.
Hi, No i can't, i want to do this with .htaccess file only.Thanks.
Link to comment
Share on other sites

You could route the 404s to a PHP file, then test if the requested file is an image..htaccessErrorDocument 404 /error.phperror.php (edit as necessary)

<?phpecho '<h1>error!</h1>';if (preg_match('/\.(css|png|jpg|jpeg|gif|bmp|swf|flv)$/',$_SERVER['REQUEST_URI']))        echo 'Image file not found<br />';echo '<pre>';var_dump($_SERVER);echo '</pre>';

Link to comment
Share on other sites

You could route the 404s to a PHP file, then test if the requested file is an image..htaccessErrorDocument 404 /error.phperror.php (edit as necessary)
<?phpecho '<h1>error!</h1>';if (preg_match('/\.(css|png|jpg|jpeg|gif|bmp|swf|flv)$/',$_SERVER['REQUEST_URI']))        echo 'Image file not found<br />';echo '<pre>';var_dump($_SERVER);echo '</pre>';

Thanks, Very very good! :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...