Skip to content
This repository was archived by the owner on Dec 2, 2017. It is now read-only.

Integrated automatic locale redirect #33

Merged
merged 1 commit into from
Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 34 additions & 2 deletions docker/caddy.conf
Original file line number Diff line number Diff line change
@@ -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"
}