This .htaccess file implements a sophisticated geo-redirection system for a WordPress website using LiteSpeed server. It automatically redirects users to country-specific subdirectories based on their geographic location while maintaining SEO-friendly URLs and proper caching mechanisms.
The .htaccess file is organized into several distinct sections:
๐ .htaccess Structure
โโโ ๐ซ Exclusion Rules (Lines 3-19)
โโโ ๐ Geo-Redirection Rules (Lines 21-90)
โโโ โก LiteSpeed Cache Configuration (Lines 92-134)
โโโ ๐๏ธ Browser Cache Settings (Lines 135-176)
โโโ ๐ง WordPress Core Rules (Lines 178-192)
โโโ ๐ LiteSpeed Module Settings (Lines 193-200)
This section prevents certain URLs from being processed by the geo-redirection system.
RewriteCond %{REQUEST_URI} ^/wp-load\.php$ [NC]
RewriteRule ^ - [L]
Explanation:
/wp-load.php (case-insensitive)-) and stop processing ([L] = Last rule)RewriteCond %{REQUEST_URI} ^/robots\.txt$ [NC]
RewriteRule ^ - [L]
Explanation:
/robots.txtRewriteCond %{REQUEST_URI} ^/sitemap_index\.xml$ [NC]
RewriteRule ^ - [L]
Explanation:
# Exclude if URL contains a country code
# RewriteCond %{REQUEST_URI} ^/(au|at|ca|fr|de|ie|it|ch|es|uk|us|lu|li)(/|$) [NC]
# RewriteRule ^ - [L]
Explanation:
# Exclude if URL contains wp-json or wp-admin
RewriteCond %{REQUEST_URI} (wp-json|wp-admin|wp-login|wp-content|wp-includes|wc-admin) [NC]
RewriteCond %{REQUEST_URI} !wc-api [NC]
RewriteCond %{REQUEST_URI} !wp-json [NC]
RewriteRule ^ - [L]
Explanation:
!wc-api = NOT wc-api)This is the core geo-redirection system that routes users based on their country.
# USA (no redirect, just pass through)
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^ - [L]
Explanation:
# Australia
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AU$
RewriteCond %{REQUEST_URI} !^/(au|at|ca|fr|de|ie|it|ch|es|uk|us|lu|li|ch-fr|ch-it|ca-fr)(/|$) [NC]
RewriteCond %{REQUEST_URI} !wp-json [NC]
RewriteRule ^(.*)$ /au/$1 [R=302,L,QSA]
Explanation:
GEOIP_COUNTRY_CODE = AU)/au/ subdirectory with 302 redirect, preserving query stringsPattern Repeats for Each Country:
/at/ (Lines 31-35)/ca/ (Lines 37-41)| **France & Luxembourg (FR | LU)** โ /fr/ (Lines 43-47) |
/de/ (Lines 49-53)/ie/ (Lines 55-59)/it/ (Lines 61-65)| **Switzerland & Liechtenstein (CH | LI)** โ /ch/ (Lines 67-71) |
/es/ (Lines 73-77)# United Kingdom & Default
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^GB$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(AU|AT|CA|FR|DE|IE|IT|CH|LI|ES|GB|US|LU)$
RewriteCond %{REQUEST_URI} !^/(au|at|ca|fr|de|ie|it|ch|es|uk|us|lu|li|ch-fr|ch-it|ca-fr)(/|$) [NC]
RewriteCond %{REQUEST_URI} !uk [NC]
RewriteRule ^(.*)$ /uk/$1 [R=302,L,QSA]
Explanation:
GB) OR/uk/ subdirectory# If no GEOIP_COUNTRY_CODE is set, redirect to /uk/ as default
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^$
RewriteCond %{REQUEST_URI} !^/(au|at|ca|fr|de|ie|it|ch|es|uk|us|lu|li|ch-fr|ch-it|ca-fr)(/|$) [NC]
RewriteCond %{REQUEST_URI} !wp-json [NC]
RewriteRule ^(.*)$ /uk/$1 [R=302,L,QSA]
Explanation:
Advanced caching configuration for LiteSpeed server.
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule litespeed/debug/.*\.log$ - [F,L]
RewriteRule \.litespeed_conf\.dat - [F,L]
Explanation:
### marker ASYNC start ###
RewriteCond %{REQUEST_URI} /wp-admin/admin-ajax\.php
RewriteCond %{QUERY_STRING} action=async_litespeed
RewriteRule .* - [E=noabort:1]
### marker ASYNC end ###
Explanation:
### marker MOBILE start ###
RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+ismobile]
### marker MOBILE end ###
Explanation:
### marker LOGIN COOKIE start ###
RewriteRule .? - [E="Cache-Vary:wp-wpml_current_language,,wp-postpass_4c6019f2292405368530c583968c4201"]
### marker LOGIN COOKIE end ###
Explanation:
### marker WEBP start ###
RewriteCond %{HTTP_ACCEPT} image/webp [OR]
RewriteCond %{HTTP_USER_AGENT} iPhone.*Version/(1[4-9]|[2-9][0-9]|[1-9][0-9]{2,}).*Safari [OR]
RewriteCond %{HTTP_USER_AGENT} Firefox/([6-9][0-9]|[1-9][0-9]{2,})
RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]
### marker WEBP end ###
Explanation:
### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
CacheKeyModify -qs:clickid
CacheKeyModify -qs:mpid
### marker DROPQS end ###
Explanation:
Long-term browser caching for static assets.
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType application/pdf A31557600
ExpiresByType image/x-icon A31557600
# ... (multiple file types)
</IfModule>
Explanation:
Standard WordPress rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Explanation:
Additional LiteSpeed configuration.
<IfModule Litespeed>
SetEnv noabort 1
</IfModule>
Explanation:
graph TD
A[User Request] --> B{Is wp-load.php?}
B -->|Yes| C[Allow - No Redirect]
B -->|No| D{Is robots.txt?}
D -->|Yes| C
D -->|No| E{Is sitemap_index.xml?}
E -->|Yes| C
E -->|No| F{Is WordPress Admin/API?}
F -->|Yes| C
F -->|No| G{Country Code = US?}
G -->|Yes| C
G -->|No| H{Country Code = AU?}
H -->|Yes| I{URL has country code?}
I -->|Yes| C
I -->|No| J[Redirect to /au/]
H -->|No| K{Country Code = AT?}
K -->|Yes| L{URL has country code?}
L -->|Yes| C
L -->|No| M[Redirect to /at/]
K -->|No| N{Country Code = CA?}
N -->|Yes| O{URL has country code?}
O -->|Yes| C
O -->|No| P[Redirect to /ca/]
N -->|No| Q{Country Code = FR or LU?}
Q -->|Yes| R{URL has country code?}
R -->|Yes| C
R -->|No| S[Redirect to /fr/]
Q -->|No| T{Country Code = DE?}
T -->|Yes| U{URL has country code?}
U -->|Yes| C
U -->|No| V[Redirect to /de/]
T -->|No| W{Country Code = IE?}
W -->|Yes| X{URL has country code?}
X -->|Yes| C
X -->|No| Y[Redirect to /ie/]
W -->|No| Z{Country Code = IT?}
Z -->|Yes| AA{URL has country code?}
AA -->|Yes| C
AA -->|No| BB[Redirect to /it/]
Z -->|No| CC{Country Code = CH or LI?}
CC -->|Yes| DD{URL has country code?}
DD -->|Yes| C
DD -->|No| EE[Redirect to /ch/]
CC -->|No| FF{Country Code = ES?}
FF -->|Yes| GG{URL has country code?}
GG -->|Yes| C
GG -->|No| HH[Redirect to /es/]
FF -->|No| II{Country Code = GB or Unknown?}
II -->|Yes| JJ{URL has country code?}
JJ -->|Yes| C
JJ -->|No| KK[Redirect to /uk/]
II -->|No| LL{No GeoIP Data?}
LL -->|Yes| MM{URL has country code?}
MM -->|Yes| C
MM -->|No| NN[Default Redirect to /uk/]
style A fill:#e1f5fe
style C fill:#c8e6c9
style J fill:#fff3e0
style M fill:#fff3e0
style P fill:#fff3e0
style S fill:#fff3e0
style V fill:#fff3e0
style Y fill:#fff3e0
style BB fill:#fff3e0
style EE fill:#fff3e0
style HH fill:#fff3e0
style KK fill:#fff3e0
style NN fill:#ffcdd2
| Country Code | Country/Region | Redirect Path | Notes |
|---|---|---|---|
US |
United States | No redirect | Primary market |
AU |
Australia | /au/ |
ย |
AT |
Austria | /at/ |
ย |
CA |
Canada | /ca/ |
ย |
FR |
France | /fr/ |
Also handles Luxembourg |
LU |
Luxembourg | /fr/ |
Shares French content |
DE |
Germany | /de/ |
ย |
IE |
Ireland | /ie/ |
ย |
IT |
Italy | /it/ |
ย |
CH |
Switzerland | /ch/ |
Also handles Liechtenstein |
LI |
Liechtenstein | /ch/ |
Shares Swiss content |
ES |
Spain | /es/ |
ย |
GB |
United Kingdom | /uk/ |
Also default fallback |
| Unknown | Any other country | /uk/ |
Default fallback |
| No GeoIP | GeoIP failure | /uk/ |
Safety net |
The system also supports these language-specific paths (though not actively redirected to):
/ch-fr/ - Switzerland (French)/ch-it/ - Switzerland (Italian)/ca-fr/ - Canada (French)%{ENV:GEOIP_COUNTRY_CODE} environment variable# Test geo-redirection
curl -I https://tradik.com/ -H "X-Forwarded-For: 1.2.3.4"
# Test with Google Bot
curl -I https://tradik.com/ -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
# Test specific country
curl -I https://tradik.com/ -H "CF-IPCountry: AU"
This documentation covers the complete .htaccess configuration for the tradik.com geo-redirection system. For technical support or modifications, ensure proper testing in a staging environment first.