Apache Server configuration support - Writing an Rewrite exception for one specific file?

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > December 2005 > Writing an Rewrite exception for one specific file?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Writing an Rewrite exception for one specific file?
Carl Rogers

2005-12-19, 6:09 pm

Hi,

For the past several months, I've been using the following code to prevent
image-hotlinking on my domain:

RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://subdomain.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://subdomain.domain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

That said, it's been an effective tool! Approximately~15% of all
error-codes each month are now "403". One problem though... Sometimes in
haste, I (incorrectly) post URLs on Usenet groups using .JPG extensions when
it should be .HTML. E.g., here's a URL I posted last night:

http://hwy-shields.calrog.com/i-10-pima.jpg
-when it should have been-
http://hwy-shields.calrog.com/i-10-pima.html

....When I make these types of mistakes, is there any way I could redirect
"/specific-file.jpg" to "specific-file.html"?

(FYI--for the time being, I've disabled hotlink protection due to high
demand for the "i-10-pima.jpg" file. So if you access the file today, the
file will load.)

Thanks,

Carl Rogers
-----------------
Calrog.com, Pictures of Highway Shields: http://hwy-shields.calrog.com
Highway Shield & Travel Literature: http://www.lulu.com/calrog-bookstore


Jim Hayter

2005-12-19, 6:09 pm

Carl Rogers wrote:
> Hi,
>
> For the past several months, I've been using the following code to prevent
> image-hotlinking on my domain:
>
> RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://subdomain.domain.com/.*$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://subdomain.domain.com$ [NC]
> RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
>
> That said, it's been an effective tool! Approximately~15% of all
> error-codes each month are now "403". One problem though... Sometimes in
> haste, I (incorrectly) post URLs on Usenet groups using .JPG extensions when
> it should be .HTML. E.g., here's a URL I posted last night:
>
> http://hwy-shields.calrog.com/i-10-pima.jpg
> -when it should have been-
> http://hwy-shields.calrog.com/i-10-pima.html
>
> ....When I make these types of mistakes, is there any way I could redirect
> "/specific-file.jpg" to "specific-file.html"?


Try this - make sure it put it in the config before the above rules.

RewriteRule ^/i-10-pima.jpg/?$ /i-10-pima.html [NC]

HTH,
Jim
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com