|
|
@@ -1,6 +1,6 @@
|
|
|
#!/bin/bash
|
|
|
# info: Adding force redirect to domain
|
|
|
-# options: USER DOMAIN REDIRECT [CUSTOM]
|
|
|
+# options: USER DOMAIN REDIRECT HTTPCODE
|
|
|
# labels: hestia web
|
|
|
#
|
|
|
# example: v-add-web-domain-redirect user domain.tld domain.tld
|
|
|
@@ -8,6 +8,7 @@
|
|
|
# example: v-add-web-domain-redirect user domain.tld shop.domain.tld
|
|
|
# example: v-add-web-domain-redirect user domain.tld different-domain.com
|
|
|
# example: v-add-web-domain-redirect user domain.tld shop.different-domain.com
|
|
|
+# example: v-add-web-domain-redirect user domain.tld different-domain.com 302
|
|
|
#
|
|
|
# Function creates a forced redirect to a domain
|
|
|
|
|
|
@@ -20,7 +21,7 @@
|
|
|
user=$1
|
|
|
domain=$2
|
|
|
redirect=$3
|
|
|
-
|
|
|
+code=${4-301}
|
|
|
|
|
|
# Includes
|
|
|
source $HESTIA/func/main.sh
|
|
|
@@ -31,8 +32,9 @@ source $HESTIA/conf/hestia.conf
|
|
|
# Verifications #
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
-check_args '3' "$#" 'USER DOMAIN REDIRECT'
|
|
|
+check_args '3' "$#" 'USER DOMAIN REDIRECT [HTTP-CODE]'
|
|
|
is_format_valid 'user' 'domain'
|
|
|
+is_number_format_valid "$code" "code"
|
|
|
is_object_valid 'user' 'USER' "$user"
|
|
|
is_object_unsuspended 'user' 'USER' "$user"
|
|
|
is_object_valid 'web' 'DOMAIN' "$domain"
|
|
|
@@ -46,26 +48,29 @@ check_hestia_demo_mode
|
|
|
# Action #
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
-
|
|
|
-
|
|
|
# Check if proxy is active
|
|
|
if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
|
|
|
conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
|
|
|
sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
|
|
|
fi
|
|
|
# Insert redirect commands
|
|
|
-if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
|
|
|
- echo "if (\$host != \"$redirect\") {" > $conf
|
|
|
- echo " return 301 \$scheme://$redirect\$request_uri;" >> $conf
|
|
|
- echo "}" >> $conf
|
|
|
-
|
|
|
- if [ ! -e "$sconf" ]; then
|
|
|
- ln -s "$conf" "$sconf"
|
|
|
- fi
|
|
|
-else
|
|
|
- echo "Non supported please use .htaccess instead"
|
|
|
- exit 2;
|
|
|
-fi
|
|
|
+#if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
|
|
|
+# echo "if (\$host != \"$redirect\") {" > $conf
|
|
|
+# echo " return $code \$scheme://$redirect\$request_uri;" >> $conf
|
|
|
+# echo "}" >> $conf
|
|
|
+#
|
|
|
+# if [ ! -e "$sconf" ]; then
|
|
|
+# ln -s "$conf" "$sconf"
|
|
|
+# fi
|
|
|
+#else
|
|
|
+ if [ ! -e "$HOMEDIR/$user/web/$domain/public_html/.htaccess" ]; then
|
|
|
+ conf="$HOMEDIR/$user/web/$domain/public_html/.htaccess"
|
|
|
+ echo "redirect $code http://$redirect" > $conf
|
|
|
+ else
|
|
|
+ conf="$HOMEDIR/$user/web/$domain/public_html/.htaccess"
|
|
|
+ echo "redirect $code http://$redirect" >> $conf
|
|
|
+ fi
|
|
|
+#fi
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
# Hestia #
|