@@ -42,22 +42,36 @@ is_object_unsuspended 'user' 'USER' "$user"
4242is_object_valid ' web' ' DOMAIN' " $domain "
4343is_object_unsuspended ' web' ' DOMAIN' " $domain "
4444
45+ requesturi=0
4546if [[ " $3 " =~ http://| https:// ]]; then
4647 scheme_check=1
4748 scheme=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); echo $url["scheme"];' " $redirect " )
4849 host=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); echo $url["host"];' " $redirect " )
4950 path=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); if(!empty($url["path"])){echo $url["path"];}' " $redirect " )
51+ port=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); if(!empty($url["port"])){echo $url["port"];}' " $redirect " )
52+
5053 host=$( idn2 --quiet " $host " )
5154 redirect=" $scheme ://$host$path "
55+ if [ -n " $port " ]; then
56+ redirect=" $scheme ://$host :$port$path "
57+ fi
58+
5259 isValidUrl=$( php -r ' $url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' " $redirect " )
5360 if [ -z " $isValidUrl " ]; then
5461 check_result $E_INVALID " Invalid redirect"
5562 fi
5663else
5764 host=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); echo $url["host"];' " http://$redirect " )
5865 path=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); if(!empty($url["path"])){echo $url["path"];}' " http://$redirect " )
66+ port=$( $HESTIA_PHP -r ' $url=parse_url($argv[1]); if(!empty($url["port"])){echo $url["port"];}' " $redirect " )
67+
5968 host=$( idn2 --quiet " $host " )
69+
6070 redirect=" $host$path "
71+ if [ -n " $port " ]; then
72+ redirect=" $host :$port$path "
73+ fi
74+
6175 isValidUrl=$( php -r ' $url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' " http://$redirect " )
6276 if [ -z " $isValidUrl " ]; then
6377 check_result $E_INVALID " Invalid redirect"
@@ -77,16 +91,33 @@ if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
7791 sconf=" $HOMEDIR /$user /conf/web/$domain /nginx.ssl.conf_redirect"
7892fi
7993
94+ # Prevent $request_uri being added if ends in .html
95+ requesturi=0
96+ if [ -n " $path " ]; then
97+ lastchr=${path# ${path% ?} }
98+ if [ " $lastchr " = " /" ]; then
99+ requesturi=1
100+ fi
101+ fi
102+
80103# Insert redirect commands
81104if [ -n " $PROXY_SYSTEM " ] || [ " $WEB_SYSTEM " = ' nginx' ]; then
82105 if [ " $scheme_check " = 1 ]; then
83- echo " return $code $redirect \$ request_uri;" > $conf
106+ if [ " $requesturi " = 1 ]; then
107+ echo " return $code $redirect \$ request_uri;" > $conf
108+ else
109+ echo " return $code $redirect ;" > $conf
110+ fi
84111 if [ ! -e " $sconf " ]; then
85112 ln -s " $conf " " $sconf "
86113 fi
87114 else
88115 echo " if (\$ host != \" $redirect \" ) {" > $conf
89- echo " return $code \$ scheme://$redirect \$ request_uri;" >> $conf
116+ if [ " $requesturi " = 1 ]; then
117+ echo " return $code \$ scheme://$redirect \$ request_uri;" >> $conf
118+ else
119+ echo " return $code \$ scheme://$redirect ;" >> $conf
120+ fi
90121 echo " }" >> $conf
91122
92123 if [ ! -e " $sconf " ]; then
0 commit comments