Forum Moderators: phranque

Message Too Old, No Replies

.htaccess question

Rewriting missing images

         

shady

2:07 am on Oct 31, 2003 (gmt 0)

10+ Year Member



Hi folks!

I have a directory from the root of my domain: /img
Under normal circumstances, images are picked up from html using URLs such as <img src="http://domain.com/img/image01.jpg">

Can I setup .htaccess in this subdirectory to return a "default" image if one is not specified: (<img src="http://domain.com/img/">)

Many thanks
Shady!

jdMorgan

3:04 pm on Oct 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



shady,

Sure, it's a simple two-line rewrite, but we try to avoid "write my code for me" threads around here. Why not try it to figure it out for yourself, and post again if you get stuck.

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

sun818

3:10 pm on Oct 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi shady, I asked a similar question previously. Something like an "image not available" graphic?

jdMorgan

3:25 pm on Oct 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sun818,

Not quite the same here; In this case, 'missing' is defined as 'missing in the requested URL'.

Jim

sun818

3:52 pm on Oct 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Could you write an index.html that displayed a default image or possibly redirect you to a graphic?

shady

4:40 pm on Oct 31, 2003 (gmt 0)

10+ Year Member



Thanks sun818

I'll give that a go! I use .htaccess a lot and had already tried to use it for this scenario but I didn't get it to work. Please don't think that I want code written without trying myself first!

Shady!

RobinC

5:36 pm on Oct 31, 2003 (gmt 0)

10+ Year Member



Why not just use the DirectoryIndex command with the name of the default image? Save having to mod_rewrite anything...

Robin

sun818

5:51 pm on Oct 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks RobinC, that what I was trying to suggest - I wasn't aware of the technical term. :)