Monday, January 2, 2023
HomeWordPress DevelopmentIs there a solution to redirect folks from a web page on...

Is there a solution to redirect folks from a web page on my .com web site to a corresponding web page on my .co.uk web site if they’re within the UK


I am hoping for a little bit of assist or to be pointed in the best path!

I’ve three web sites:

  1. a .co.uk web site for the UK
  2. a .ie web site for Eire
  3. a .com web site
    for everybody else

The .com was my essential website, and folks in Eire and the UK are used to visiting it, however now I want them to go to their native website, the place the content material has been tailor-made for them.

I host on WP Engine and have the GeoTarget add-on. For the previous 12 months, I have been utilizing the code beneath to redirect everybody, however it is a bit blunt. It sends everybody to the house web page of their native website, even when they have been attempting to entry a particular web page e.g. ‘companies’.

    perform country_geo_redirect() {
    if ( is_user_logged_in() ) {
    return;
    }

    $nation = getenv('HTTP_GEOIP_COUNTRY_CODE');
    if ( $nation == "GB" ) {
    wp_redirect( 'https://www.uk-website.co.uk', 301 );
    exit;
    } else if ( $nation == "IE" ) {
    wp_redirect( 'https://www.irish-website.ie', 301 );
    exit;
    }
    }
    add_action('init', 'country_geo_redirect');

It might be significantly better if I might edit this and redirect them to a web page similar to the one they tried to go to e.g. in the event that they tried to go to companies, I ought to redirect them to the companies web page on the .ie or .co.uk

Any concepts?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments