Integrated automatic locale redirect

This commit is contained in:
Thomas Boerger 2016-12-25 16:11:44 +01:00 коммит произвёл Kim "BKC" Carlbäcker
Родитель 4262f09992
Коммит 6f2c0d1b2d
2 изменённых файлов: 43 добавлений и 9 удалений

Просмотреть файл

@ -2,13 +2,15 @@ FROM alpine:edge
EXPOSE 80
RUN apk update && \
apk add \
caddy \
mailcap && \
rm -rf \
/var/cache/apk/*
apk add wget mailcap ca-certificates && \
rm -rf /var/cache/apk/* && \
wget -O /tmp/caddy.tar.gz "https://caddyserver.com/download/build?os=linux&arch=amd64&features=locale%2Csearch" && \
mkdir -p /tmp/caddy && \
tar xvzf /tmp/caddy.tar.gz -C /tmp/caddy && \
cp /tmp/caddy/caddy /usr/sbin/caddy && \
rm -rf /tmp/caddy*
CMD ["/usr/sbin/caddy", "-conf", "/etc/caddy/caddy.conf"]
CMD ["/usr/sbin/caddy", "-conf", "/etc/caddy.conf"]
COPY docker/caddy.conf /etc/caddy/caddy.conf
COPY docker/caddy.conf /etc/caddy.conf
COPY public /srv/www

Просмотреть файл

@ -1,7 +1,39 @@
:80 {
root /srv/www
errors {
404 /404.html
locale en-US zh-CN zh-TW pt-BR nl-NL {
detect header
}
redir 301 {
if {path} match ^/$
/ /{>Detected-Locale}/
}
rewrite /en-US/ {
regexp (.*)
to /en-us/{1}
}
rewrite /zh-CN/ {
regexp (.*)
to /zh-cn/{1}
}
rewrite /zh-TW/ {
regexp (.*)
to /zh-tw/{1}
}
rewrite /pt-BR/ {
regexp (.*)
to /pt-br/{1}
}
rewrite /nl-NL/ {
regexp (.*)
to /nl-nl/{1}
}
header / Vary "Accept-Language"
}