cancel
Showing results for 
Search instead for 
Did you mean: 

Image redirect

ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Image redirect

I have posted images on 1 or 2 hobby forums over the past year or so. I'd like  to have a clear-out and remove some of the older images now but this would show the missing image icon on my posts. I'd prefer to show another default image that says something like: "This image is no longer available" or something a bit friendlier like that. I found some htaccess code in a forum somewhere but this just gave me a server error when I tried it.
So, is this possible to do this in htaccess? To summarise, I want to redirect any requests for any images that are missing to a default image.
Thanks for any help.
PS. I'm not talking about hotlinking.
24 REPLIES 24
Chris
Legend
Posts: 17,724
Thanks: 600
Fixes: 169
Registered: ‎05-04-2007

Re: Image redirect

Looks like some of the replies on this forum are pretty helpful.
Former Plusnet Staff member. Posts after 31st Jan 2020 are not on behalf of Plusnet.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

Hello Chris, that is the forum and topic I found! The problem with it is this:
Options +FollowSymLinks
which caused the server error until I commented it out.
Peter_Vaughan
Grafter
Posts: 14,469
Registered: ‎30-07-2007

Re: Image redirect

You should not need it as you aren't using symbolic links.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

Thank you Peter, that stops the server error though it is not replacing the image with my default image.
I suppose what I really need to do is learn a bit about whatever language that script is written in so I can work out what I need to do.  I'm alright with C++ but this is alien to me. Do you know what the language is?
Many thanks.
EDIT:
Found a list of the rules etc, seems a bit complex to start leaning for this one thing.
Perhaps someone could tell me what is wrong with this please:

RewriteEngine on
RewriteCond %{REQUEST_URI} !-U
RewriteRule /subdir/\.(gif|jpg|jpeg|png)$ default.png

where the htaccess file is in root (htdocs), the images are in subdir, and default.png is in root also.
I'm not sure whether you should start the path with a forward slash etc. but I've tried various combinations.
Thanks for any help.
Peter_Vaughan
Grafter
Posts: 14,469
Registered: ‎30-07-2007

Re: Image redirect

Try
RewriteRule \.(gif¦jpg¦jpeg|png)$ /default.png
Chris
Legend
Posts: 17,724
Thanks: 600
Fixes: 169
Registered: ‎05-04-2007

Re: Image redirect

Quote from: Peter
Try
RewriteRule \.(gif¦jpg¦jpeg|png)$ /default.png

With this would default.png need to be in the same directory as the htaccess file?
Former Plusnet Staff member. Posts after 31st Jan 2020 are not on behalf of Plusnet.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

RewriteRule \.(gif|jpg|jpeg|png)$ /default.png 

This still does not show the replacement image -- which has been uploaded before anyone asks Wink
Thank you anyway.
@Peter, default.png is in the same directory as the htaccess file.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

I still can't get this to work, does anyone have any other ideas as to what may be wrong?
Thanks for any help.
Barry.
oliverb
Grafter
Posts: 606
Registered: ‎02-08-2007

Re: Image redirect

I don't know if I can help but FWIW you have my sympathy. I've only ever been able to make RewriteRule work with to return a redirect. I've wasted an afternoon trying to get an internal rewrite to work.
In my case all I want to do is check if a file exists (which works) and if it doesn't then rewrite to another directory.
Incidentally I'm fairly sure "alias" does work as I've used it, though its nothing like as powerfull as mod_rewrite.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

Thank you oliverb. Perhaps it's something to do with the way plusnet have things set up then -- I know next to nothing about this kind of thing.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

Is there a plusnet employee that could say for certain whether this is possible to do or not?
I thank you.
oliverb
Grafter
Posts: 606
Registered: ‎02-08-2007

Re: Image redirect

At risk of resurrecting a dead thread...
It occured to me that a redirect would do what you're asking, and probably would work.
The rule would be something like:
RewriteRule \.(gif¦jpg¦jpeg|png)$ http://www.yourdomain.co.uk/default.png [L,R]
The difference is that with the option instead of failing to return the image it returns a URL as a redirect. The browser then looks up that URL to get the image.
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Image redirect

@oliverb
I appreciate you trying to help. I just tried that with and then with but I still just get a 404 error. Still open to any suggestions.
ianscales
Grafter
Posts: 75
Registered: ‎30-07-2007

Re: Image redirect

I might be barking up the wrong tree here but, if your not already using a customised 404 page could you not use that to display the 'image not available' message.
I know the above would be a bit messy but at least it should fix it for now.
Ian