Skip to content

Commit 1bdc2db

Browse files
authored
Merge pull request #12 from leMaik/misc-updates
Allow not retaining the path, do not add trailing slashes and update nginx
2 parents e006d97 + 64f7cb9 commit 1bdc2db

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM nginx:1.15-alpine
1+
FROM nginx:1.25-alpine
22

33
COPY start.sh /usr/local/bin/
44

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Possible redirect targets include domains (`mydomain.net`), paths (`mydomain.net
1717
**Example:** `$ docker run --rm -d -e REDIRECT_TARGET=mydomain.net -p 80:80 morbz/docker-web-redirect`
1818

1919
### Paths are retained ###
20-
The URL path and GET parameters are retained. That means that a request to `http://myolddomain.net/index.php?page=2` will be redirected to `http://mydomain.net/index.php?page=2` when `REDIRECT_TARGET=mydomain.net` is set.
20+
The URL path and GET parameters are retained by default. That means that a request to `http://myolddomain.net/index.php?page=2` will be redirected to `http://mydomain.net/index.php?page=2` when `REDIRECT_TARGET=mydomain.net` is set. If you do not want to retain the path and GET parameters, set the environment variable `RETAIN_PATH` to `false`.
2121

2222
### Permanent redirects ###
2323
Redirects are, by default, permanent (HTTP status code 301). That means browsers will cache the redirect and will go directly to the new site on further requests. Also search engines will recognize the new domain and change their URLs. This means this image is not suitable for temporary redirects e.g. for site maintenance.

start.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ else
1111
if ! [[ $REDIRECT_TARGET =~ ^https?:// ]]; then
1212
REDIRECT_TARGET="http://$REDIRECT_TARGET"
1313
fi
14-
15-
# Add trailing slash
16-
if [[ ${REDIRECT_TARGET:length-1:1} != "/" ]]; then
17-
REDIRECT_TARGET="$REDIRECT_TARGET/"
18-
fi
1914
fi
2015

2116
# Default to 80
@@ -25,13 +20,24 @@ if [ ! -z "$PORT" ]; then
2520
LISTEN="$PORT"
2621
fi
2722

28-
cat <<EOF > /etc/nginx/conf.d/default.conf
29-
server {
30-
listen ${LISTEN};
23+
: ${RETAIN_PATH:='true'}
24+
if [ "$RETAIN_PATH" = "true" ]; then
25+
cat <<EOF > /etc/nginx/conf.d/default.conf
26+
server {
27+
listen ${LISTEN};
28+
29+
rewrite ^(.*)\$ ${REDIRECT_TARGET}\$1 ${REDIRECT_TYPE};
30+
}
31+
EOF
32+
else
33+
cat <<EOF > /etc/nginx/conf.d/default.conf
34+
server {
35+
listen ${LISTEN};
3136
32-
rewrite ^/(.*)\$ ${REDIRECT_TARGET}\$1 ${REDIRECT_TYPE};
33-
}
37+
rewrite ^(.*)\$ ${REDIRECT_TARGET} ${REDIRECT_TYPE};
38+
}
3439
EOF
40+
fi
3541

3642

3743
echo "Listening to $LISTEN, Redirecting HTTP requests to ${REDIRECT_TARGET}..."

0 commit comments

Comments
 (0)