hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : .htaccess missing image replacement
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)
Forum Jump

.htaccess missing image replacement

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 12-20-2007, 11:36 PM
EverSpeed EverSpeed is offline
Junior Guru Wannabe
 
Join Date: Feb 2004
Posts: 55

.htaccess missing image replacement


I have been fiddling with an .htaccess file trying to get it to show a default "Image Not Available" image in place of a 404 error. I have found code in other forums that has worked for others, but does nothing for me:

Code:
Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}!-f 
RewriteCond %{REQUEST_URI} (.*).(gif|jpg|jpeg|png)$ 
RewriteRule ^(.*) noimage.gif
and this one which several people said worked for them

Code:
RewriteCond %{ENV:ERROR404} \.(jpg|gif|png)$ [NC]
RewriteRule ^.*$ noimage.gif [L]
Anyone had experience with this? The webserver is Apache on CentOS 5.

Thanks,
Aaron

Reply With Quote


Sponsored Links
  #2  
Old 12-21-2007, 12:11 AM
david510 david510 is offline
Web Hosting Master
 
Join Date: Oct 2004
Location: Kerala, India
Posts: 4,617
To redirect the 404 not found error to a image located in your web directory, use the following rule inside the .htaccess

ErrorDocument 404 /path/to/nopage_image.gif

__________________
David | www.cliffsupport.com
Affordable Server Management Solutions sales AT cliffsupport DOT com
iWebManager | Access WHM from iPhone and Android

Reply With Quote
  #3  
Old 12-21-2007, 12:35 AM
foobic foobic is offline
Community Liaison 2.0
 
Join Date: Feb 2005
Location: Australia
Posts: 5,112
But of course that will redirect all missing pages to the same image. If you still want to use mod_rewrite, try this:
Code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$ 
RewriteRule .* path/to/noimage.gif [L]
Using either method you must ensure that noimage.gif exists and is where you've told Apache to find it.

__________________
Chris

"Learn from the mistakes of others. You can never live long enough to make them all yourself." - Groucho Marx

Reply With Quote
Sponsored Links
  #4  
Old 12-21-2007, 01:05 AM
EverSpeed EverSpeed is offline
Junior Guru Wannabe
 
Join Date: Feb 2004
Posts: 55
Yeah, I need it to replace only missing image files, since documents are already rerouted to a custom search page, so I do need to stick with mod_rewrite.

Is the path to noimage.gif relative to the site's public_html folder or to the server root?

Thanks!

Reply With Quote
  #5  
Old 12-21-2007, 01:09 AM
EverSpeed EverSpeed is offline
Junior Guru Wannabe
 
Join Date: Feb 2004
Posts: 55
Nevermind, I got it working on the first try by using the path relative to the site's folder. Perfect! This is going to save me so much time, not having to create individual "image not available" thumbnails.

Thanks!!!!!

Reply With Quote
  #6  
Old 12-21-2007, 01:09 AM
david510 david510 is offline
Web Hosting Master
 
Join Date: Oct 2004
Location: Kerala, India
Posts: 4,617
If you are placing the rule inside the file .htaccess inside /home/username/public_html and the noimage.gif lies inside the same folder, you can specify the path as follows

RewriteRule .* /noimage.gif [L]

__________________
David | www.cliffsupport.com
Affordable Server Management Solutions sales AT cliffsupport DOT com
iWebManager | Access WHM from iPhone and Android

Reply With Quote
  #7  
Old 01-04-2012, 03:55 AM
rcpkrc rcpkrc is offline
WHT Addict
 
Join Date: Jul 2006
Posts: 161
thanks for sharing this lovely tips, l was looking for a code for the missing images in wordpress.

__________________
Breaking News | Video
serversupport.us for sale if u have nice offers..

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
WHIR Events return to the Big Apple next week Blog 2012-10-12 14:00:38
New York Times Article on Data Center Efficiency Only Tells Half of the Story: Data Center Knowledge Web Hosting News 2012-09-24 15:52:28
Irish Web Host LetsHost Sending Billing Reminders to Customers via Text Message Web Hosting News 2012-03-13 17:00:48
Go Daddy Helping Customers Repair Compromised Sites Web Hosting News 2011-09-16 14:35:03
Web Host SoftLayer Launches Public Image Repository for Cloud Templates Web Hosting News 2011-06-08 14:56:19


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?