I wish to redirect all URLs with underscores to their dashed equivalent.
E.g. /nederland/amsterdam/car_rental
becomes /nederland/amsterdam/car-rental
. For this I'm using the technique described here: How to replace underscore to dash with Nginx. So my location block is matched to:
location ~ (_)
But I only want to do this on URLs not in the /admin
namespace. To accomplish this I tried combining the regex with a negative lookup: Regular expression to match a line that doesn't contain a word?. The location now matches with:
(?=^(?!\/admin))(?=([^_]*))
Rubular reports the string /nederland/amsterdam/car_rental
to match the regex, while /admin/stats_dashboard
is not matched, just as I want it. However when I apply this rule to the nginx config, the site ends up in redirect loops. Is there anything I've overlooked?
UPDATE: I don't actually want to rewrite anything in the /admin
namespace. The underscore-to-dash rewrite should only take place on all URLs not in the /admin
namespace.