Using .htaccess to easily redirect AU traffic to au.example.com

Hello Team

My .htaccess skills aren’t really up to scratch so I’m asking for some help from the community :slight_smile:

I have a website at example.com and some some content relevant only to Australia at au.example.com - I want to automatically redirect any customer visiting from Australia to au.example.com while obviously allowing users from any other region to to go to example.com as normal.

I also have the domain behind Cloudflare, therefore I have the IP Geolocation setting on, which allows the IP Geolocation information from the CF-IPCountry HTTP header.

I already had a Google around and I found this for .htaccess:

SetEnvIf CF-IPCountry “(.)$” Country=$1
RewriteCond %{ENV:Country} BE
RewriteRule ^(.
)$ https://be.example.com/$1 [R,L]

This is as per https://community.cloudflare.com/t/redirecting-specific-country-to-sub-domain/12688/6

Will this snippet be valid? I would really appreciate any help with this task!

Thanks so much!

@contact17 Hey there. I’m curious to know if you got this working. Did you use the snippet you posted above or a variation of the one in this KB article - https://support.cloudways.com/use-geoip-with-your-application/ ?

Hey there, I never actually attempted to implement this either way. I had a plugin already set up at the time to take care of these redirects, and my intention was to remove that plugin and replace it with the above code instead.

In the end, I decided to keep the plugin after all. Sorry that I couldn’t be of more help :slight_smile:

Ah okay. Thanks for following up to let me know. If you don’t mind, which plugin did you use to handle the redirection?