diff --git a/src/freedombone-app-matrix b/src/freedombone-app-matrix
index 75b8f6a17d27cf5112a79be60f8a999b9139b7ef..bc46d38cd4c0d19c3035997063033aefa1460d3d 100755
--- a/src/freedombone-app-matrix
+++ b/src/freedombone-app-matrix
@@ -882,14 +882,7 @@ function matrix_update_riot_config {
     if [ ! -d "/var/www/$RIOT_DOMAIN_NAME/htdocs" ]; then
         return
     fi
-    if [ -f "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$RIOT_DOMAIN_NAME.json" ]; then
-        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${RIOT_DOMAIN_NAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$RIOT_DOMAIN_NAME.json"
-        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${RIOT_DOMAIN_NAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$RIOT_DOMAIN_NAME.json"
-    fi
-    if [ -f "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$MATRIX_ONION_HOSTNAME.json" ]; then
-        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_ONION_HOSTNAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$MATRIX_ONION_HOSTNAME.json"
-        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_ONION_HOSTNAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$MATRIX_ONION_HOSTNAME.json"
-    fi
+    riot_set_default_homeserver
 }
 
 function install_matrix {
diff --git a/src/freedombone-app-riot b/src/freedombone-app-riot
index b7f450572c2f396f34a9a6db3ab33fc91a5138cc..e6f288821d0e1fc956d3f86f95122563e1aae2fa 100755
--- a/src/freedombone-app-riot
+++ b/src/freedombone-app-riot
@@ -62,9 +62,20 @@ function riot_set_default_homeserver {
         if [ ! "$MATRIX_DOMAIN_NAME" ]; then
             read_config_param MATRIX_DOMAIN_NAME
         fi
+
+        if [ -f "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$RIOT_DOMAIN_NAME.json" ]; then
+            sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${RIOT_DOMAIN_NAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$RIOT_DOMAIN_NAME.json"
+            sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${RIOT_DOMAIN_NAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$RIOT_DOMAIN_NAME.json"
+        fi
+
         sed -i "s|https://matrix.org|https://$MATRIX_DOMAIN_NAME|g" /var/www/$RIOT_DOMAIN_NAME/htdocs/bundles/*/*.js
         sed -i "s|https://vector.im|https://$MATRIX_DOMAIN_NAME|g" /var/www/$RIOT_DOMAIN_NAME/htdocs/bundles/*/*.js
     else
+        if [ -f "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$MATRIX_ONION_HOSTNAME.json" ]; then
+            sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_ONION_HOSTNAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$MATRIX_ONION_HOSTNAME.json"
+            sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_ONION_HOSTNAME}\",|g" "/var/www/$RIOT_DOMAIN_NAME/htdocs/config.$MATRIX_ONION_HOSTNAME.json"
+        fi
+
         if [ -f /var/lib/tor/hidden_service_matrix/hostname ]; then
             MATRIX_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_matrix/hostname)
             sed -i "s|https://matrix.org|http://$MATRIX_ONION_HOSTNAME|g" /var/www/$RIOT_DOMAIN_NAME/htdocs/bundles/*/*.js