• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

wordpress/htaccess - set default image for any missing one

I've had a heck of a time with this.

I want to set up a default image to take the place of any missing one (in the uploads folder, or sitewide even) on my wordpress site.

I thought perhaps I could set up something like this in an htaccess file in my uploads folder:
------------------

ErrorDocument 404 /default.jpg

---------------------

That had no effect, I still get a broken image image on webpages with missing images and if I go to the url of the image, I get the standard 404 page.

Also tried:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} \.(jpg|png)$ [NC]
RewriteRule .* /default.jpg     #and a variety of paths in case that was the problem.

and a number of other things, none worked.

I went to my top level directory's htaccess and entered this, which looked impressive:

<FilesMatch "\.(gif|jpe?g|png|ico)$">
ErrorDocument 403 http://www.(mysite.com)/wp-content/uploads/default-gen1-165x165.png
ErrorDocument 404 http://www.(mysite.com)/wp-content/uploads/default-gen1-165x165.png
ErrorDocument 500 http://www.(mysite.com)/wp-content/uploads/default-gen1-165x165.png
</FilesMatch>

But it didn't work.

Here's what I currently have in my top level .htaccess file:

-------------------------------------------------------

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#change 'alerts' to 'news'
RewriteRule ^section/alerts(.*)$ section/news$1 [R=301,L]
RewriteRule ^section/sales(.*)$ section/shopping$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#change 'alerts' to 'news'
RewriteRule ^section/alerts/(.*)$ section/news/$1 [R=301,L]

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

--------------------------------------------

I've been working on this problem for hours and am fit to be tied!

Would appreciate some help!

Chris
0
St_Aug_Beach_Bum
Asked:
St_Aug_Beach_Bum
  • 3
  • 2
1 Solution
 
Edwin HofferTechnical ExpertCommented:
Hello,

Use this code in your .htaccess file:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ not-found.gif [NC,L]

Open in new window


Change not-found.gif to your image

Thanks
Edwin
0
 
St_Aug_Beach_BumAuthor Commented:
Hi Edwin,

I put that in the .htaccess of my uploads folder, doesn't work though, goes to the server's default not found page,

Chris
0
 
Edwin HofferTechnical ExpertCommented:
If the above code is not working then download and install: WP 404 Images Fix plugin https://wordpress.org/plugins/wp-404-images-fix/

and Put an alternative image for 404 not found images:

alternative image
0
 
St_Aug_Beach_BumAuthor Commented:
HI Edwin,

Man, this is a stubborn problem. I installed/activated the plugin and have tried both 'hide' and 'alternative' options with them having no effect at all. I'm using wp 3.9.1,

Chris
0
 
Edwin HofferTechnical ExpertCommented:
Both are working fine for me, I am using WordPress 3.9.2.

Add full URL in alternative image and check. Instead of refreshing the page use Ctrl+F5 for hard refresh and check again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now