I need to redirect web requests of the form /{language}-{country}/{file}
to:
/{language}-{country}/{file}
if it exists, otherwise/{language}/{file}
if it exists, otherwise/en-US/{file}
The existing .htaccess
fulfils requirements 1 and 3. What changes do I need to fulfil requirement 2?
.htaccess
:
Options +FollowSymLinks
RewriteEngine On
RewriteCond $0 !i18n/en-US [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(i18n)/([^/]+)/(.*)$ $1/en-US/$3 [NC,L]
Update:
My new .htaccess meets the functional requirement but seems over-complicated. How can I simplify it?
# If not exists {language}-{country}, try {language}
RewriteCond $0 i18n
RewriteCond $0 !en-us
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $0 ^(.*)(i18n)/(\w+)(-\w+)*/(.*)$
RewriteCond E:/webserver/app/$2/$3/$5 -f
RewriteRule ^(.*)(i18n)/(\w+)(-\w+)*/(.*)$ /app/$2/$3/$5 [L]
# If not exists {language}-{country} or {language}, try /en-us/
RewriteCond $0 i18n
RewriteCond $0 !en-us
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $0 ^(.*)(i18n)/(\w+)(-\w+)*/(.*)$
RewriteCond E:/webserver/app/$2/$3/$5 !-f
RewriteCond E:/webserver/app/$2/en-us/$5 -f
RewriteRule ^(.*)(i18n)/(\w+)(-\w+)*/(.*)$ /app/$2/en-us/$5 [L]