Hello I'm trying to make redirections in wordpress for example if I have ip starting on 73.... I want to redirect to subpage. How and where can I do it? I have to use .htaccess file?
Asked
Active
Viewed 77 times
-2
-
1what ip are you referring to ? – May 19 '14 at 20:27
-
I will have diffrent ip from diffrent cities and If I have ip from London I want to redirect to subpage for London. – marcin.g May 19 '14 at 20:29
-
its called geolocation, not very reliable. http://stackoverflow.com/questions/10562265/i-want-to-find-current-location-of-user-in-php/ (and many more) – May 19 '14 at 20:30
-
This might help: http://www.wpjedi.com/geo-redirect-wordpress-plugins-for-geo-targeting/ – anubhava May 19 '14 at 20:33
1 Answers
1
The code below is basic and will work sometimes, but users can spoof their IP address if they want to.
$userIp = explode('.', $_SERVER['REMOTE_ADDR']);
if (($userIp[0].'.'.$userIp[1].'.'.$userIp[2]) == '192.168.2')
{
header("location:sub.domain.com");
}

dcclassics
- 896
- 1
- 12
- 38
-
-
-
-
Well I didn't expect you to be looking for 192 IP ranges either... It's not hard to finish from here. – dcclassics May 19 '14 at 20:39
-
I'm not looking for 192 IP but you helped me at all thank you very much :) – marcin.g May 19 '14 at 20:40
-
See edit again, you can see how to add more than one to find different ranges. – dcclassics May 19 '14 at 20:41
-
Also, if you start getting crazy, a switch would be much more easy to follow than if statements. – dcclassics May 19 '14 at 20:42