afshin.m Posted June 23, 2010 Share Posted June 23, 2010 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 More sharing options...
wirehopper Posted June 23, 2010 Share Posted June 23, 2010 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 More sharing options...
afshin.m Posted June 24, 2010 Author Share Posted June 24, 2010 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 More sharing options...
wirehopper Posted June 24, 2010 Share Posted June 24, 2010 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 More sharing options...
afshin.m Posted June 24, 2010 Author Share Posted June 24, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.