Allow 3 ip's, redirect for other ip's and redirect to mobile site

Viewed 65

I want to allow three IPs to my site and show a message for other IPs. Also, I want to redirect to a mobile site if the site is visited with a mobile device.

This all in htaccess. I tried if statements in htaccess but for some reason they won't work.

What i need is this


if ((ip=1.2.3.4 OR ip=5.6.7.8 OR ip=9.10.11.12) AND ismobile=true)
{
    redirect to mobile site
}
elseif ((ip=1.2.3.4 OR ip=5.6.7.8 OR ip=9.10.11.12) AND ismobile=false)
{
    redirect to normal site
}
else
{
    redirect to site with message
}
1 Answers

With your shown samples could you please try following. Change yoursite your actual domain name. Also please make sure you clear browser cache before testing your URLs.

<IfModule mod_rewrite.c>

RewriteEngine ON
RewriteCond %{REMOTE_ADDR} ^((1\.2\.3\.4)|(5\.6\.7\.8)|(9\.10\.11\.12))$
RewriteRule ^ http://yoursite.com/ [R=301,L]

RewriteCond %{REMOTE_ADDR} !^((1\.2\.3\.4)|(5\.6\.7\.8)|(9\.10\.11\.12))$
RewriteRule ^ message.php [L]
</IfModule>

Here is the Online regex demo for above regex.

Related