Redirecting users by IP in Apache
May 12, 2008 1:16 PM
Subscribe
How do I redirect incoming website visitors to an external site by IP address?
I'm the general sysadmin here and don't do much web stuff other than simple content updating, but I think I'm on the right track with adding this bit of mod_rewrite code to the end of the httpd.conf file...
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^12\.345\.678\.9$
RewriteCond %{REQUEST_URI} ^/index.php$ [NC]
RewriteRule ^/(.*) http://test.foo.com/$1 [R]
Any ideas why this isn't working?
(apache 1.3.33 on OS X)
posted by Oktober to computers & internet (7 comments total)
2 users marked this as a favorite
RewriteEngine On
RewriteLog /tmp/log.txt
RewriteLogLevel 9
This will log every step apache takes while churning your request through mod_rewrite. You get to see what apache is actually doing and you should be able to figure out where your logic is failing . Bonus OS X tip; use the Console app in the "/Application/Utilities" folder to monitor the log file. It's kind of a GUI for tail.
Don't forget to turn logging off once you go to production, as it'll make your server crawl.
posted by alan at 1:42 PM on May 12