simplifier le code, et éviter les / multiples à la suite
This commit is contained in:
parent
d8ad7f2748
commit
7223a8b292
|
@ -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.'
|
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=
|
proxy_enabled=
|
||||||
infile=
|
infile=
|
||||||
outfile="RewriteRules.conf"
|
outfile="RewriteRules.conf"
|
||||||
|
@ -136,7 +149,7 @@ for rule in "${rules[@]}"; do
|
||||||
echo "${rule#=}" >>"$outfile"
|
echo "${rule#=}" >>"$outfile"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IFS=:; set -- $rule; unset IFS
|
IFS=:; set -- $rule; unset IFS
|
||||||
index=1
|
index=1
|
||||||
done=
|
done=
|
||||||
|
@ -158,6 +171,10 @@ for rule in "${rules[@]}"; do
|
||||||
index=$(($index + 1))
|
index=$(($index + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# mettre en forme prefix s'il est défini
|
||||||
|
[ -n "$prefix" ] && prefix="$prefix
|
||||||
|
"
|
||||||
|
|
||||||
if [ "$thishost" == "$host" ]; then
|
if [ "$thishost" == "$host" ]; then
|
||||||
host=
|
host=
|
||||||
fi
|
fi
|
||||||
|
@ -188,34 +205,28 @@ for rule in "${rules[@]}"; do
|
||||||
if [ -n "$host" ]; then
|
if [ -n "$host" ]; then
|
||||||
# sur un autre hôte
|
# sur un autre hôte
|
||||||
if [ -n "$noslash" ]; then
|
if [ -n "$noslash" ]; then
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix" ${trail:+\$1}) [L${options:+,$options}]" >>"$outfile"
|
||||||
}RewriteRule ^/$src${trail:+(.*)} $prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}${trail:+\$1} [L${options:+,$options}]" >>"$outfile"
|
setx url joinurl "http://$thishost" "$usrc"
|
||||||
url="http://$thishost/$usrc"
|
setx proxy_url joinurl "prot://$host/cgi-bin/WebObjects" "$dest" "$suffix"
|
||||||
proxy_url="$prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}"
|
|
||||||
else
|
else
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
||||||
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix" "\$1") [L${options:+,$options}]" >>"$outfile"
|
||||||
echo "${prefix:+$prefix
|
setx url joinurl "http://$thishost" "$usrc/"
|
||||||
}RewriteRule ^/$src/(.*) $prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}/\$1 [L${options:+,$options}]" >>"$outfile"
|
setx proxy_url joinurl "prot://$host/cgi-bin/WebObjects" "$dest" "$suffix/"
|
||||||
url="http://$thishost/$usrc/"
|
|
||||||
proxy_url="$prot://$host/cgi-bin/WebObjects/$dest${suffix:+/$suffix}/"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# sur le même hôte
|
# sur le même hôte
|
||||||
if [ -n "$noslash" ]; then
|
if [ -n "$noslash" ]; then
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl /cgi-bin/WebObjects "$dest" "$suffix" ${trail:+\$1}) [L,P${options:+,$options}]" >>"$outfile"
|
||||||
}RewriteRule ^/$src${trail:+(.*)} /cgi-bin/WebObjects/$dest${suffix:+/$suffix}${trail:+\$1} [L,P${options:+,$options}]" >>"$outfile"
|
setx url joinurl "http://$thishost" "$usrc"
|
||||||
url="http://$thishost/$usrc"
|
setx proxy_url joinurl "prot://$thishost/cgi-bin/WebObjects" "$dest" "$suffix"
|
||||||
proxy_use=1
|
proxy_use=1
|
||||||
proxy_url="http://$thishost/cgi-bin/WebObjects/$dest${suffix:+/$suffix}"
|
|
||||||
else
|
else
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
||||||
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl /cgi-bin/WebObjects "$dest" "$suffix" "\$1") [L,P${options:+,$options}]" >>"$outfile"
|
||||||
echo "${prefix:+$prefix
|
setx url joinurl "http://$thishost" "$usrc/"
|
||||||
}RewriteRule ^/$src/(.*) /cgi-bin/WebObjects/$dest${suffix:+/$suffix}/\$1 [L,P${options:+,$options}]" >>"$outfile"
|
setx proxy_url joinurl "prot://$thishost/cgi-bin/WebObjects" "$dest" "$suffix/"
|
||||||
url="http://$thishost/$usrc/"
|
|
||||||
proxy_use=1
|
proxy_use=1
|
||||||
proxy_url="http://$thishost/cgi-bin/WebObjects/$dest${suffix:+/$suffix}/"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -223,32 +234,26 @@ for rule in "${rules[@]}"; do
|
||||||
if [ -n "$host" ]; then
|
if [ -n "$host" ]; then
|
||||||
# sur un autre hôte
|
# sur un autre hôte
|
||||||
if [ -n "$noslash" ]; then
|
if [ -n "$noslash" ]; then
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl "$prot://$host" "$dest" "$suffix" ${trail:+\$1}) [L${options:+,$options}]" >>"$outfile"
|
||||||
}RewriteRule ^/$src${trail:+(.*)} $prot://$host/$dest${suffix:+/$suffix}${trail:+\$1} [L${options:+,$options}]" >>"$outfile"
|
setx url joinurl "http://$thishost" "$usrc"
|
||||||
url="http://$thishost/$usrc"
|
setx proxy_url joinurl "prot://$host" "$dest" "$suffix"
|
||||||
proxy_url="$prot://$host/$dest${suffix:+/$suffix}"
|
|
||||||
else
|
else
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
||||||
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl "$prot://$host" "$dest" "$suffix" "\$1") [L${options:+,$options}]" >>"$outfile"
|
||||||
echo "${prefix:+$prefix
|
setx url joinurl "http://$thishost" "$usrc/"
|
||||||
}RewriteRule ^/$src/(.*) $prot://$host/$dest${suffix:+/$suffix}/\$1 [L${options:+,$options}]" >>"$outfile"
|
setx proxy_url joinurl "$prot://$host" "$dest" "$suffix/"
|
||||||
url="http://$thishost/$usrc/"
|
|
||||||
proxy_url="$prot://$host/$dest${suffix:+/$suffix}/"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# sur le même hôte
|
# sur le même hôte
|
||||||
if [ -n "$noslash" ]; then
|
if [ -n "$noslash" ]; then
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(joinurl / "$dest" "$suffix" ${trail:+\$1})${options:+ [$options]}" >>"$outfile"
|
||||||
}RewriteRule ^/$src${trail:+(.*)} /$dest${suffix:+/$suffix}${trail:+\$1}${options:+ [$options]}" >>"$outfile"
|
setx url joinurl "http://$thishost" "$usrc"
|
||||||
url="http://$thishost/$usrc"
|
setx proxy_url joinurl "http://$thishost" "$dest" "$suffix"
|
||||||
proxy_url="http://$thishost/$dest${suffix:+/$suffix}"
|
|
||||||
else
|
else
|
||||||
echo "${prefix:+$prefix
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
||||||
}RewriteRule ^/$src\$ /$src/" >>"$outfile"
|
echo "${prefix}RewriteRule ^/$src/(.*) $(joinurl / "$dest" "$suffix" "\$1")${options:+ [$options]}" >>"$outfile"
|
||||||
echo "${prefix:+$prefix
|
setx url joinurl "http://$thishost" "$usrc/"
|
||||||
}RewriteRule ^/$src/(.*) /$dest${suffix:+/$suffix}/\$1${options:+ [$options]}" >>"$outfile"
|
setx proxy_url joinurl "http://$thishost" "$dest" "$suffix/"
|
||||||
url="http://$thishost/$usrc/"
|
|
||||||
proxy_url="http://$thishost/$dest${suffix:+/$suffix}/"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue