simplifier le code, et éviter les / multiples à la suite

This commit is contained in:
Jephté Clain 2014-08-18 17:11:16 +04:00
parent d8ad7f2748
commit 7223a8b292
1 changed files with 46 additions and 41 deletions

View File

@ -82,6 +82,19 @@ Dans les exemples donnés ci-dessus, $URL est l'\''url générée par la réécr
et $proxy_acls la valeur du champ proxy_acls spécifiée ci-dessus.'
}
function joinurl() {
# joindre chaque élément de $1..@ par /, en évitant les slashes en double
local i url
for i in "$@"; do
if [ -n "$url" ]; then
url="${url%/}/${i#/}"
else
url="$i"
fi
done
[ -n "$url" ] && echo "$url"
}
proxy_enabled=
infile=
outfile="RewriteRules.conf"
@ -136,7 +149,7 @@ for rule in "${rules[@]}"; do
echo "${rule#=}" >>"$outfile"
continue
fi
IFS=:; set -- $rule; unset IFS
index=1
done=
@ -158,6 +171,10 @@ for rule in "${rules[@]}"; do
index=$(($index + 1))
done
# mettre en forme prefix s'il est défini
[ -n "$prefix" ] && prefix="$prefix
"
if [ "$thishost" == "$host" ]; then
host=
fi
@ -188,34 +205,28 @@ for rule in "${rules[@]}"; do
if [ -n "$host" ]; then
# sur un autre hôte
if [ -n "$noslash" ]; then
echo "${prefix:+$prefix
}RewriteRule ^/$src${trail:+(.*)} $prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}${trail:+\$1} [L${options:+,$options}]" >>"$outfile"
url="http://$thishost/$usrc"
proxy_url="$prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}"
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix" ${trail:+\$1}) [L${options:+,$options}]" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc"
setx proxy_url joinurl "prot://$host/cgi-bin/WebObjects" "$dest" "$suffix"
else
echo "${prefix:+$prefix
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix:+$prefix
}RewriteRule ^/$src/(.*) $prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}/\$1 [L${options:+,$options}]" >>"$outfile"
url="http://$thishost/$usrc/"
proxy_url="$prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}/"
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix" "\$1") [L${options:+,$options}]" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc/"
setx proxy_url joinurl "prot://$host/cgi-bin/WebObjects" "$dest" "$suffix/"
fi
else
# sur le même hôte
if [ -n "$noslash" ]; then
echo "${prefix:+$prefix
}RewriteRule ^/$src${trail:+(.*)} /cgi-bin/WebObjects/$dest${suffix:+/$suffix}${trail:+\$1} [L,P${options:+,$options}]" >>"$outfile"
url="http://$thishost/$usrc"
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl /cgi-bin/WebObjects "$dest" "$suffix" ${trail:+\$1}) [L,P${options:+,$options}]" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc"
setx proxy_url joinurl "prot://$thishost/cgi-bin/WebObjects" "$dest" "$suffix"
proxy_use=1
proxy_url="http://$thishost/cgi-bin/WebObjects/$dest${suffix:+/$suffix}"
else
echo "${prefix:+$prefix
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix:+$prefix
}RewriteRule ^/$src/(.*) /cgi-bin/WebObjects/$dest${suffix:+/$suffix}/\$1 [L,P${options:+,$options}]" >>"$outfile"
url="http://$thishost/$usrc/"
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl /cgi-bin/WebObjects "$dest" "$suffix" "\$1") [L,P${options:+,$options}]" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc/"
setx proxy_url joinurl "prot://$thishost/cgi-bin/WebObjects" "$dest" "$suffix/"
proxy_use=1
proxy_url="http://$thishost/cgi-bin/WebObjects/$dest${suffix:+/$suffix}/"
fi
fi
else
@ -223,32 +234,26 @@ for rule in "${rules[@]}"; do
if [ -n "$host" ]; then
# sur un autre hôte
if [ -n "$noslash" ]; then
echo "${prefix:+$prefix
}RewriteRule ^/$src${trail:+(.*)} $prot://$host/$dest${suffix:+/$suffix}${trail:+\$1} [L${options:+,$options}]" >>"$outfile"
url="http://$thishost/$usrc"
proxy_url="$prot://$host/$dest${suffix:+/$suffix}"
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl "$prot://$host" "$dest" "$suffix" ${trail:+\$1}) [L${options:+,$options}]" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc"
setx proxy_url joinurl "prot://$host" "$dest" "$suffix"
else
echo "${prefix:+$prefix
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix:+$prefix
}RewriteRule ^/$src/(.*) $prot://$host/$dest${suffix:+/$suffix}/\$1 [L${options:+,$options}]" >>"$outfile"
url="http://$thishost/$usrc/"
proxy_url="$prot://$host/$dest${suffix:+/$suffix}/"
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl "$prot://$host" "$dest" "$suffix" "\$1") [L${options:+,$options}]" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc/"
setx proxy_url joinurl "$prot://$host" "$dest" "$suffix/"
fi
else
# sur le même hôte
if [ -n "$noslash" ]; then
echo "${prefix:+$prefix
}RewriteRule ^/$src${trail:+(.*)} /$dest${suffix:+/$suffix}${trail:+\$1}${options:+ [$options]}" >>"$outfile"
url="http://$thishost/$usrc"
proxy_url="http://$thishost/$dest${suffix:+/$suffix}"
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl / "$dest" "$suffix" ${trail:+\$1})${options:+ [$options]}" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc"
setx proxy_url joinurl "http://$thishost" "$dest" "$suffix"
else
echo "${prefix:+$prefix
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix:+$prefix
}RewriteRule ^/$src/(.*) /$dest${suffix:+/$suffix}/\$1${options:+ [$options]}" >>"$outfile"
url="http://$thishost/$usrc/"
proxy_url="http://$thishost/$dest${suffix:+/$suffix}/"
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl / "$dest" "$suffix" "\$1")${options:+ [$options]}" >>"$outfile"
setx url joinurl "http://$thishost" "$usrc/"
setx proxy_url joinurl "http://$thishost" "$dest" "$suffix/"
fi
fi
fi