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
2021user=$1
2122domain=$2
2223redirect=$3
23-
24+ code= ${4-301}
2425
2526# Includes
2627source $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] '
3536is_format_valid ' user' ' domain'
37+ is_number_format_valid " $code " " code"
3638is_object_valid ' user' ' USER' " $user "
3739is_object_unsuspended ' user' ' USER' " $user "
3840is_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
5252if [ " $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"
5555fi
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 #
0 commit comments