I am trying to redirect all traffic to my site from a country to a sub-domain. I am using the following method to redirect the traffic.
RewriteEngine on
SetEnvIf CF-IPCountry "(.*)$" Country=$1
RewriteCond %{ENV:Country} ID
RewriteRule ^(.*)$ https://us.example.com/$1 [R,L]
ID is the country code, using Cloudflare IP Geolocation for the same.
Now coming to my issue. Using the above method only the homepage is being redirected, sub-pages of my main domain are not redirected. I came across a couple of methods where you have manually enter the details of each page. Is there a way to redirect all sub-pages to the sub-domain.
Need the below functionality,
https://example.com/page-1/ ---------> https://us.example.com/page-1/
https://example.com/page-2/ ---------> https://us.example.com/page-2/
.htaccess
file?