title: Apache rewrite subnet ip range
body: <p>Can someone please tell me how to put the following IP ranges (belongs to Cloudfront) in a mod_rewrite?
  I am looking to redirect the non-www requests for example.com to www.example.com BUT not redirect any IP address coming from IP Ranges below:</p>
  
  <pre><code>54.192.0.0/16
  54.230.0.0/16
  54.239.128.0/18
  54.239.192.0/19
  54.240.128.0/18
  204.246.164.0/22
  204.246.168.0/22
  204.246.174.0/23 
  204.246.176.0/20 
  205.251.192.0/19 
  205.251.249.0/24 
  205.251.250.0/23 
  205.251.252.0/23 
  205.251.254.0/24 
  216.137.32.0/19 
  </code></pre>
  
  <p>I used a tool called <strong>rgxg</strong> to convert all of the above from CIDR to Regex and created the following entries in my httpd.conf:</p>
  
  <pre><code>    RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
  
      RewriteCond %{HTTP:X-FORWARDED-FOR} !54\.192(\.(25[0-5]|2[0-4][0-9]||1[0-9]{2}|[1-9]?[0-9])){2} 
  
      RewriteRule ^/(.*)?$ http://www.example.com/$1 [R=301,NC,NE,L]
  </code></pre>
  
  <p>I have added all the ip ranges in my RewriteCond entries but included only the first one as I didn't want to clutter this post.  The rule don't appear to work.  If I put just a single IP address, it works without a problem.</p>
  
  <p>Can someone please check and see what I'm doing wrong?</p>
  
  <p>Thanks!
  -Ma</p>