• I am trying to set up wildcard redirection based on country.
    I have .com website and .ca website with exact same page paths. The only difference people will see if the price/tax difference. That’s why 2 different website.

    example.com/somepage
    should redirect to
    example.ca/somepage

Viewing 1 replies (of 1 total)
  • Thread Starter solodave99

    (@solodave99)

    Ok I was able to configure the below and it works fine.

    function country_geo_redirect() {
    
    //get the country 
    	$country = getenv('HTTP_GEOIP_COUNTRY_CODE');
    //get the URI path of current url
    	$path = $_SERVER['REQUEST_URI'];
    //create the destination url using the above found path
    	$ca_url = "https://yoursite.ca" . $path;
    
    //do the magic
    
    	if ( $country == "CA" ) {
    
    	wp_redirect( $ca_url, 301 );
    
    	     exit;
    		}
    
    }
    
    add_action('init', 'country_geo_redirect');
Viewing 1 replies (of 1 total)
  • The topic ‘How to set up WildCard Redirect?’ is closed to new replies.