Skip to content

Commit 903df9c

Browse files
committed
Add support Apache2 need to be tested
1 parent b286969 commit 903df9c

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

bin/v-add-web-domain-redirect

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/bin/bash
22
# info: Adding force redirect to domain
3-
# options: USER DOMAIN REDIRECT [CUSTOM]
3+
# options: USER DOMAIN REDIRECT HTTPCODE
44
# labels: hestia web
55
#
66
# example: v-add-web-domain-redirect user domain.tld domain.tld
77
# example: v-add-web-domain-redirect user domain.tld www.domain.tld
88
# example: v-add-web-domain-redirect user domain.tld shop.domain.tld
99
# example: v-add-web-domain-redirect user domain.tld different-domain.com
1010
# example: v-add-web-domain-redirect user domain.tld shop.different-domain.com
11+
# example: v-add-web-domain-redirect user domain.tld different-domain.com 302
1112
#
1213
# Function creates a forced redirect to a domain
1314

@@ -20,7 +21,7 @@
2021
user=$1
2122
domain=$2
2223
redirect=$3
23-
24+
code=${4-301}
2425

2526
# Includes
2627
source $HESTIA/func/main.sh
@@ -31,8 +32,9 @@ source $HESTIA/conf/hestia.conf
3132
# Verifications #
3233
#----------------------------------------------------------#
3334

34-
check_args '3' "$#" 'USER DOMAIN REDIRECT'
35+
check_args '3' "$#" 'USER DOMAIN REDIRECT [HTTP-CODE]'
3536
is_format_valid 'user' 'domain'
37+
is_number_format_valid "$code" "code"
3638
is_object_valid 'user' 'USER' "$user"
3739
is_object_unsuspended 'user' 'USER' "$user"
3840
is_object_valid 'web' 'DOMAIN' "$domain"
@@ -46,26 +48,29 @@ check_hestia_demo_mode
4648
# Action #
4749
#----------------------------------------------------------#
4850

49-
50-
5151
# Check if proxy is active
5252
if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
5353
conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
5454
sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
5555
fi
5656
# Insert redirect commands
57-
if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
58-
echo "if (\$host != \"$redirect\") {" > $conf
59-
echo " return 301 \$scheme://$redirect\$request_uri;" >> $conf
60-
echo "}" >> $conf
61-
62-
if [ ! -e "$sconf" ]; then
63-
ln -s "$conf" "$sconf"
64-
fi
65-
else
66-
echo "Non supported please use .htaccess instead"
67-
exit 2;
68-
fi
57+
#if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
58+
# echo "if (\$host != \"$redirect\") {" > $conf
59+
# echo " return $code \$scheme://$redirect\$request_uri;" >> $conf
60+
# echo "}" >> $conf
61+
#
62+
# if [ ! -e "$sconf" ]; then
63+
# ln -s "$conf" "$sconf"
64+
# fi
65+
#else
66+
if [ ! -e "$HOMEDIR/$user/web/$domain/public_html/.htaccess" ]; then
67+
conf="$HOMEDIR/$user/web/$domain/public_html/.htaccess"
68+
echo "redirect $code http://$redirect" > $conf
69+
else
70+
conf="$HOMEDIR/$user/web/$domain/public_html/.htaccess"
71+
echo "redirect $code http://$redirect" >> $conf
72+
fi
73+
#fi
6974

7075
#----------------------------------------------------------#
7176
# Hestia #

bin/v-delete-web-domain-redirect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
4949
rm $HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
5050
rm $HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
5151
else
52-
echo "Non supported please use .htaccess instead"
53-
exit 2;
52+
conf="$HOMEDIR/$user/web/$domain/public_html/.htaccess"
53+
echo "redirect $code http://$redirect" >> $conf
5454
fi
5555

5656
#----------------------------------------------------------#

0 commit comments

Comments
 (0)