• zen047

    (@zen047)


    I have a WP question hoping someone can point me in right direction.

    I need to redirect my store customers to a specific country subdomain for all pages, posts, and products. The main domain and subdomain have the same content, so I only need to change the URL.

    For Example: https://www.example.com main page https://www.example.com/page1 , https://www.example.com/product1

    For US visitor: us.example.com main page us.example.com/page1 , us.example.com/product1

    For US visitor: uk.example.com main page uk.example.com/page1 , uk.example.com/product1

    thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @zen047 ??

    Others might have better suggestions but two approaches come to mind.

    1. .htaccess – IP-based geolocation would be more efficient at the server level but would require a module such as GeoIP as .htaccess files alone wouldn’t be able to do the job. This would avoid having to load WordPress for every request only to redirect some of them.
    2. Geolocation Service API – Using a geolocation service, logic could be added to your theme’s function.php file to determine the request’s origin, and then redirect as required. This would come at quite a cost though.

    Personally, I’d only really consider #1 as an option.

    I hope that helps some!

    Thread Starter zen047

    (@zen047)

    hello @aaronrobertshaw I appreciate your reply. Would it be feasible to explain how to do it?

    I have experimented with certain methods, but they have always caused issues. For example, some only work on the main page and with code in function.php ,the subdomain gets repeated when i click on any page.

    uk.example.com click… about….. take you to uk.uk.example.com/about

    thank you

    • This reply was modified 2 months, 3 weeks ago by zen047.
    • This reply was modified 2 months, 3 weeks ago by zen047.

    Would it be feasible to explain how to do it?

    I think using the .htaccess file to handle the redirections to subdomains is your best bet. The link I shared in my last reply explains .htaccess files better than I can here.

    As for a geolocation service, that isn’t something I can help with, sorry. How you’d set it up etc would likely change depending on the service but they should offer support on that front.

    Your hosting provider is also your best option in general for support on both .htaccess files and adding geolocation modules to your hosting setup, if it doesn’t already have one for just this kind of purpose.

    the subdomain gets repeated when i click on any page.

    This sounds like your redirection needs to be a little more nuanced and check for an existing subdomain (excluding www) etc. in the URL before adding a new one.

    Another option you could look into would be to leverage a WordPress plugin for managing redirections. This would come with the downside that WordPress has to load before a URL can be redirected the first time.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.