We have a page, gateway.school.edu, where users have to fill out a recaptcha before being directed forward to our password reset. I would like any internal traffic, any user agent on our network with a 10., 172. or 192.* IP, to get passed through without having to fill out the recaptcha. So an internal user would navigate to gateway.school.edu, where apache would check for an internal IP, then send them on to reset.school.edu. External users would have to fill out the captcha before being sent to reset.school.edu

Is this possible using {REMOTE_ADDR} in apache? Something like:

#gateway.school.edu virtual host
RewriteCond %{REMOTE_ADDR} ^192.*
RewriteRule .* reset.school.edu

Is there another approach I could take to accomplish this, or would a rewrite be the best way? Syntactically, how do I define the IP ranges?

1 Answer 1


Try this:

#gateway.school.edu virtual host
RewriteCond %{REMOTE_ADDR} ^10\.(.*)$ [OR]
RewriteCond %{REMOTE_ADDR} ^172\.(.*)$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.(.*)$
RewriteRule .* reset.school.edu [R=301,L]

The .* is a wildcard. The \ escapes the . which anchors the match allowing it to be taken literally. The () may not be necessary- it is usually used to capture the value of the regular expression match into a variable. You may be able to remove them, but I left them for this example for the sake of readability. The ^ matches the beginning of the line. The $ matches the end of the line. The [OR] is obvious. The [R=301,L] is a redirect 301 and last.

  • This worked, thank you very much! A clarification if you dont mind: the L in [R=301,L] denotes Last, but what does Last mean in this context? Thanks again Oct 2, 2014 at 14:35
  • It just means that it is the last directive in the chain and to stop after processing the directive. It is a kind of close. Otherwise, mod_rewrite might get confused.
    – closetnoc
    Oct 2, 2014 at 16:41
  • In fact, these links may help but may also make anyone go cross-eyed. The .htaccess file directives are not terribly complicated, but getting into what to do can take a bit of time to get your head around. Eventually, and not too long, you will create a core of examples you can draw from. I keep a file that I refer to on my computer for occassions such as this. httpd.apache.org/docs/2.4/rewrite httpd.apache.org/docs/2.4/rewrite/intro.html httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule
    – closetnoc
    Oct 2, 2014 at 16:59
  • Thanks again closetnoc, I was able to successfully implement your suggestion, and now I have some reading to do! Oct 2, 2014 at 21:47
  • Make sure your in bed... it may put you to sleep!
    – closetnoc
    Oct 3, 2014 at 0:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.