Using Apache Mod_rewrite to redirect based on user-agent (curl)
I decided to add the ability to use curl to pull your current public IP address. In order to get this to work I used Apache Mod_rewrite to redirect based on curl’s user-agent:
First, enable the rewrite engine in your Apache configuration file. I added the following configuration under the virtual host.
RewriteEngine on
Create a Rewrite condition that matches the curl user-agent.
RewriteCond %{HTTP_USER_AGENT} ^curl/*
Create a Rewrite rule that redirects the visitor from the default page.RewriteRule ^/index.php$ /ip.php [L]