{HTTP_HOST} doesn't work

Hi,

I’m using this tester: htaccess tester
to test my htaccess rule

exmple url :
http://myDomain/images/infowindows/SPE_title.png

my rules:
RewriteCond %{HTTP_HOST} ^http://(.*)/images/infowindows/SPE_title.png$ [NC]
RewriteRule /images/infowindows/SPE_title.png$ http://%1/images/infowindows/search.png [NC,L,R=301]

returned url (according to the test) :
http://myDomain/images/infowindows/SPE_title.png

meaning the condition wasn’t met.
Can someone see my mistake?

The HTTP_HOST is just the host, i.e. myDomain. The rest of the URL is stored in %{REQUEST_URI} and I don’t think there is a variable for “http://”
But why do you have that RewriteCond? It looks completely redundant to me …


RewriteRule ^/images/infowindows/SPE_title.png$ http://%{HTTP_HOST}/images/infowindows/search.png [NC,L,R=301]

(also added the ^ at the start of the rule. are you on Apache 1.x?)

Thanks for the explanation.

RewriteRule ^/images/infowindows/SPE_title.png$ http://%{HTTP_HOST}/images/infowindows/search.png [NC,L,R=301]

but using the tester still returns the initial url

http://myDomain/images/infowindows/SPE_title.png

any idea?
btw, why do I need ^

?

using ISAPI for IIS

And if you try without the leading slash?


RewriteRule ^images/infowindows/SPE_title\\.png$ http://%{HTTP_HOST}/images/infowindows/search.png [NC,L,R=301]

BTW. You need to escape the dot in the regular expression, otherwise it will be interpreted as the special character “match any” instead of a regular dot. Just put a \ in front of it like I did above :slight_smile:

That was it !

. –> \.
and without the leading slash

Thanks a bunch !

Well I was happy to soon…

I’ll explain my aim from the beginning:
I have a server. Everytime the client asks the server for a specific image, I want the server to redirect to another image (a newer one).

My full ISAPI htaccess:
===================
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.60

RewriteEngine On
RewriteCompatibility2 On
RepeatLimit 32
RewriteBase

RewriteRule ^/Bing$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/Zynga$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/([0-9]+)$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/CT([0-9]+)$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^images/infowindows/SPE_title.png$ http://%{HTTP_HOST}/images/infowindows/search.png [NC,L,R=301]

Which I have tried in some online tester, and that seems to work well, as ca be seen here:
https://picasaweb.google.com/elad2109/ImageResourceRedirect?authkey=Gv1sRgCK6K3vegz4veDQ#5607413050992754706

However, defato I see the old image brought to the website (client) and that also appears via Fiddler - no redirection is done (and I don’t understand why !)


i see the request in Fiddler:
=========================
GET http://www108.MyHome.com/images/infowindows/SPE_ti... HTTP/1.1
Host: www108.conduitlive.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://www108.MyHome.com/bing
Cookie: __utma=264109214.1078718614.1305536197.1305547582.1305556877.4; __utmc=264109214; __utmz=264109214.1305536197.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=69165847.1285126412.1305559921.1305559921.1305559921.1; __utmb=69165847.3.10.1305559921; __utmc=69165847; __utmz=69165847.1305559921.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Pragma: no-cache
Cache-Control: no-cache


A sreenshot can be seen here:
https://picasaweb.google.com/elad2109/ImageResourceRedirect?authkey=Gv1sRgCK6K3vegz4veDQ#5607413044216373186

Does anyone have any Idea, what am I doing wrong?

Thanks in advance

You probably need a / in front of images, like you have in the other rules.

What does this slash does?

It should fix the rule … Apparently this system uses Apache 1.x syntax where you need to match the leading slash. i.e.


My full ISAPI htaccess:
===================
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.60

RewriteEngine On
RewriteCompatibility2 On
RepeatLimit 32
RewriteBase

RewriteRule ^/Bing$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/Zynga$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/([0-9]+)$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/CT([0-9]+)$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^[B][COLOR="Red"]/[/COLOR][/B]images/infowindows/SPE_title.png$ http://%{HTTP_HOST}/images/infowindows/search.png [NC,L,R=301]

Add the slash in bold red.