From 22fdb2ec5969abf6a25a53537580671471ee4ffc Mon Sep 17 00:00:00 2001 From: ewilly Date: Tue, 1 May 2018 20:34:45 +0200 Subject: [PATCH] Fix change url --- scripts/_common.sh | 4 ++-- scripts/change_url | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 7386935..502ecc8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -46,10 +46,10 @@ myynh_add_nginx_config () { # Substitute in a nginx config file only if the variable is not empty if test -n "${path_url:-}"; then if [ "${path_url:-}" != "/" ]; then - ynh_replace_string "^#sub_path_only" "" "$nginx_conf" + ynh_replace_string "^#sub_path_only " "" "$nginx_conf" ynh_replace_string "__PATH__" "$path_url" "$nginx_conf" else - ynh_replace_string "__PATH__/" "$path_url" "$nginx_conf" + ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? __PATH__/" "location\1 $path_url" "$nginx_conf" fi fi [ -n "${final_path:-}" ] && ynh_replace_string "__FINALPATH__" "$final_path" "$nginx_conf" diff --git a/scripts/change_url b/scripts/change_url index f7d1b8e..dbaaba1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -16,9 +16,9 @@ path_url_new=$YNH_APP_NEW_PATH # check the syntax [ -n "$path_url_old" ] || path_url_old="/" +path_url_old=$(ynh_normalize_url_path "$path_url_old") [ -n "$path_url_new" ] || path_url_new="/" path_url_new=$(ynh_normalize_url_path "$path_url_new") -path_url_old=$(ynh_normalize_url_path "$path_url_old") # definie useful vars nginx_conf_old="/etc/nginx/conf.d/$domain_old.d/$app.conf" @@ -34,8 +34,21 @@ change_path_url=0 if [ $change_path_url -eq 1 ] then ynh_backup_if_checksum_is_different "$nginx_conf_old" - ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $path_url_old" "location\1 $path_url_new" "$nginx_conf_old" - ynh_replace_string "return \([[:digit:]]\{3\}\) $path_url_old" "return \1 $path_url_new" "$nginx_conf_old" + if [ "$path_url_new" != "/" ]; then + if [ "^$path_url_old" != "/" ]; then + #$path_url_new != / & $path_url_old != / + ynh_replace_string "rewrite ^$path_url_old$ $path_url_old/ permanent;" "rewrite ^$path_url_new$ $path_url_new/ permanent;" "$nginx_conf_old" + ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $path_url_old" "location\1 $path_url_new" "$nginx_conf_old" + else + #$path_url_new != / & $path_url_old = / + ynh_replace_string "#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;" "rewrite ^$path_url_old$ $path_url_old/ permanent;" "$nginx_conf_old" + ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $path_url_old" "location\1 $path_url_new/" "$nginx_conf_old" + fi + else + #$path_url_new = / => $path_url_old != / + ynh_replace_string "rewrite ^$path_url_old$ $path_url_old/ permanent;" "#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;" "$nginx_conf_old" + ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $path_url_old/" "location\1 $path_url_new" "$nginx_conf_old" + fi ynh_store_file_checksum "$nginx_conf_old" fi