homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Serving Different File Than One Coded
I want to serve a different image than the one in the code

 1:56 am on Jan 7, 2009 (gmt 0)

I have a script on my website with a header graphic that refers to the script developer. Because my users/visitors log in using this script, the developer authorizes me to use my own header image as a replacement.

Only problem is that when I run the auto-update function, the developers coders send a replacement copy of their header image which overwrites mine.

I do not want to change the code in the script. Besides the fact that he did not give permission to do that, the update will probably replace the code and I would have to take the chance of making a mistake somewhere along the line.

What I would like to do is use .htaccess to serve a different image than the one that is delivered with the script, sort of like serving a different image to someone who is hotlinking.

I am awfully weak with .htaccess. Mostly because in addition to being old, tired and ugly, I am having mental absorption issues. Can't absorb much more.

If soemone could please give me some ideas (even code the whole doo-hickey) i would appreciate it.

Thanks many times, and in advance,



 2:03 am on Jan 7, 2009 (gmt 0)

The answer depends on whether the link to the "developer image" in the code refers to an image on your own site, or on theirs. If it refers to their site, then you can't use mod_rewrite to fix this, although if you're on Apache 2.x, you might be able to set up an 'output filter' to catch the page content as it's being sent out from your server, and change it there.

Otherwise, the code will be identical to the anti-hotlinking code you can find here, except that you should remove the RewriteCond that checks the referrer, as it won't be needed.



 2:18 am on Jan 7, 2009 (gmt 0)

They send the images to my server when doing their auto-update, so then I presume I need only to use the anti-hotlinking code without the REFERRER section.

Thanks again.

BTW - where is the anti-hotlinking code you mentioned? Do I just search for it, or was there supposed to be a link in your reply?



 2:23 am on Jan 7, 2009 (gmt 0)

Would this be it?

RewriteCond [mydomain...] [mydomain...] [L]


 11:33 am on Jan 7, 2009 (gmt 0)

Would this be it?

No, you're matching against a local filepath in in per-directory context. That is r->filename (full physical path like /var/www/foo) with the striped directory prefix (if in /var/www/.htaccess, result is foo).

RewriteRule ^their\.gif$ my.gif [L]


 1:13 pm on Jan 7, 2009 (gmt 0)



 3:01 pm on Jan 7, 2009 (gmt 0)

Well-explained in the Apache mod_rewrite documentation. Highly-recommended.



 3:33 pm on Jan 7, 2009 (gmt 0)

Thanks Jim.


 3:51 pm on Jan 7, 2009 (gmt 0)

I didn't understand that. It was WAY over my head.

But, using your advice as the search term, I did find an explanation at [yourhtmlsource.com...] which allowed me to understand the response from Caterham.

Thanks to both. Sorry for being so thick. I think whatever search term I was using in Google was giving me too many results and muddying the waters.

Cheers to both.


 7:45 pm on Jan 7, 2009 (gmt 0)

Post your example code to be sure you have the right version. :-)


 8:01 pm on Jan 7, 2009 (gmt 0)

So happy! It's working on the server.

Only question is, do I need the backslash before the dash in the second image filename?

REwriteEngine On
RewriteRule ^theirimage\.gif$ myimage.gif [L]
RewriteRule ^theirheader\-repeat\.gif$ myheader-repeat.gif [L]



 8:32 pm on Jan 7, 2009 (gmt 0)

You don't need to escape either hyphen in that line. Only the regular expressions anchors, character-tokens, operators, and quantifiers need to be escaped with a backslash. See the regex tutorial cited in our Charter.

Also, suggest you fix the casing of "RewriteEngine on", although it will work as-is on *almost* all servers.



 9:02 pm on Jan 7, 2009 (gmt 0)

Oops. Hadn't even noticed the E.

It's working, but will fix.

Where do I find the Charter?



 9:59 pm on Jan 7, 2009 (gmt 0)

Thanks for posting it.

Even code that "works" isn't always "right". :-)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved