#geolocationbasedredirect #cloudfront #apache
Geo-Location Based Redirects with CloudFront and Apache | Redirect Web traffic Based on Country of Origin with CloudFront
In this video let us see how to enable geo-location-based redirects with CloudFront CDN and Apache server.
Geo IP based redirection is the process of automatically redirecting a website visitor by their geolocation.
There are multiple options to enable the location-based redirects in Apache, one of the options is using a Geo IP database like the MaxMind Geo IP database to map users' IP to their location.
Maxmind Geo IP database is enabled through the Apache module.
If you are using any of the CDN e.g CloudFront provides specific headers with request location, CloudFront will detect the user’s country of origin and pass along the county code to the origin server in the CloudFront-Viewer-Country header. You can use this information to customize your responses e.g redirecting the users to a specific URL based on origin country.
As a first step white list the CloudFront-Viewer-Country header in Cloudfront distribution.
Now enable the required rewrite rules in Apache
RewriteCond %{REQUEST_URI} ^/content/we-retail.html
RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^US$
RewriteRule ^.*$ @/we-retail/us/en.html [R=302,L]
RewriteCond %{REQUEST_URI} ^/content/we-retail.html
RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^IT$
RewriteRule ^.*$ @/we-retail/it/it.html [R=302,L]
RewriteCond %{REQUEST_URI} ^/content/we-retail.html
RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^CA
RewriteRule ^.*$ @/we-retail/ca/en.html [R=302,L]
RewriteCond %{REQUEST_URI} ^/content/we-retail.html
RewriteCond %{HTTP:CLOUDFRONT-VIEWER-COUNTRY} ^FR$
RewriteRule ^.*$ @/we-retail/fr/fr.html [R=302,L]
I am using some VPN tools to initiate the connection from a different origin country.