{"id":959,"date":"2013-07-26T13:44:17","date_gmt":"2013-07-26T20:44:17","guid":{"rendered":"http:\/\/jim-zimmerman.com\/?p=959"},"modified":"2013-08-09T11:03:21","modified_gmt":"2013-08-09T18:03:21","slug":"redirect-certain-subnets-to-a-different-site-in-apache","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=959","title":{"rendered":"Redirect certain subnets to a different site in Apache."},"content":{"rendered":"<p>I did this from the httpd.conf where I have all my virtual directories defined.  I just added the following within one of those virtual directory definitions and reloaded httpd.  This will redirect anybody on the 192.168.0.0\/24 subnet to http:\/\/google.com, and the others will proceed to the directory (\/my\/website\/directory).<\/p>\n<blockquote><p>       <Directory \/my\/website\/directory><br \/>\n               RewriteEngine On<br \/>\n               RewriteBase \/<br \/>\n               RewriteCond %{REMOTE_HOST} !^192.168.0.*<br \/>\n               RewriteRule .* http:\/\/google.com [R=302,L]<br \/>\n       <\/Directory><\/p><\/blockquote>\n<p>In an .htaccess file you would just need to add the following:<\/p>\n<blockquote><p>RewriteEngine On<br \/>\n               RewriteBase \/<br \/>\n               RewriteCond %{REMOTE_HOST} !^192.168.0.*<br \/>\n               RewriteRule .* http:\/\/google.com [R=302,L]\n<\/p><\/blockquote>\n<p>If you need to redirect the cgi-bin, elsewhere:<\/p>\n<blockquote><p><Directory \"\/var\/www\/cgi-bin\"><br \/>\n        AllowOverride All<br \/>\n        RewriteEngine On<br \/>\n        RewriteBase \/<br \/>\n        RewriteCond %{REMOTE_HOST} !^192.168.0.*<br \/>\n        RewriteCond %{REMOTE_HOST} !^172.16.0.*<br \/>\n        RewriteCond %{REMOTE_HOST} !^10.0.0.*<br \/>\n        RewriteRule .* http:\/\/www.google.com [R=302,L]<br \/>\n        Options ExecCGI<br \/>\n        Options FollowSymLinks<br \/>\n        Order allow,deny<br \/>\n        Allow from all<br \/>\n<\/Directory><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I did this from the httpd.conf where I have all my virtual directories defined. I just added the following within one of those virtual directory definitions and reloaded httpd. This will redirect anybody on the 192.168.0.0\/24 subnet to http:\/\/google.com, and the others will proceed to the directory (\/my\/website\/directory). RewriteEngine On RewriteBase \/ RewriteCond %{REMOTE_HOST} !^192.168.0.* [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[120,330,331],"class_list":["post-959","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-apache","tag-httpd-conf","tag-redirect"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=959"}],"version-history":[{"count":4,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/959\/revisions"}],"predecessor-version":[{"id":963,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/959\/revisions\/963"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}