Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following Rewrite statement:

RewriteCond %{HTTP_X_SOMEHEADER} ^mystring$
RewriteCond %{REMOTE_ADDR} ^111\.222\.111\.222$ 
RewriteRule (.*) /mypage.html     [L]

The way I read this is:

IF HTTP_X_SOMEHEADER equals "mystring" 
AND  
REMOTE_ADDR equals 111.222.111.222 
THEN  
GOTO mypage.html

However what I'm seeing is that if the IP is 111.222.111.222 but HTTP-X-SOMEHEADER doesn't exist then the rule passes.

I'd like the rule to only pass if the header HTTP-X-SOMEHEADER exists and the IP is correct.

Any ideas?

share|improve this question
    
What do you mean by the rule passes? You mean if someone doesn't have the header they get redirected to mypage.html anyways? –  Philip Reynolds Sep 4 '09 at 11:29
    
Hi Phil, that's correct. Just the IP needs to match and the redirect happens. –  Elliot Tucker Sep 4 '09 at 12:21
add comment

1 Answer

up vote 2 down vote accepted

I think you need RewriteCond %{HTTP:HTTP_X_SOMEHEADER} to pick up an arbitrary HTTP header that's not in the list given in the mod_rewrite docs.

Your code matches the behaviour I would expect from the setup, so there's more going on. What's in the error log?

share|improve this answer
    
(OK, I've added the %{HTTP:...} I think I see what's happening. I have multiple RewriteCond and RewriteRule groupings and more than one of them has the RewriteRule of (.*) I think it's finding the first (.*) RewriteRule and is then checking the RewriteCond's associated with it. Basically what I'm trying to do is set up multiple RewriteCond and RewriteRule blocks that allow things through if a certain criteria is met. This means I have more than one (.*) RewriteRule. Is this the wrong way to do it? –  Elliot Tucker Sep 4 '09 at 12:22
    
Post the whole lot if you want, and we can go from there. Ideally, you want the most restrictive rule first on the list. –  CK. Sep 4 '09 at 12:43
    
CK, thanks very much. Changing the order of my rules (plus noticing an error in my regexp) fixed the problem. The above rule group is now being picked up correctly. –  Elliot Tucker Sep 4 '09 at 13:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.