-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmu-geo-redirect.php
32 lines (30 loc) · 1.14 KB
/
mu-geo-redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* Plugin Name: CDK GEO Redirect
* Description: Detect country via CloudFlare and redirect to same lang website version
* Plugin URI: https://cdk.co.il
* Author: cdk.co.il
* Version: 0.0.1
* Author URI: https://dimaminka.com
*
* Text Domain: cdk
*
*
* CDK GEO Redirect is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* CDK GEO Redirect is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
$cf = $_SERVER['HTTP_CF_IPCOUNTRY'];
$url = $_SERVER['REQUEST_URI'];
$uri_arr = explode( '/', $url );
if ( ! isset( $_COOKIE['cf_ipc'] ) && $uri_arr[1] !== 'wp-admin' && $uri_arr[1] !== 'wp-login.php' && $uri_arr[1] !== 'israel' && $cf == 'IL' ) {
setcookie( 'cf_ipc', $cf );
header( 'Location: https://' . $_SERVER['HTTP_HOST'] . '/israel' . $_SERVER['REQUEST_URI'], true, 302 );
exit;
}