I need to redirect all traffic without a subdomain to the www
subdomain (e.g, foo.com
->www.foo.com
).
The code below is working, but i know redirecting code can be brittle and might bring security flaws.
Is this a proper way of achieving the above, or is there perhaps another set of directives i should use?
host("^(?!www).+".r) { h =>
unmatchedPath { p =>
schemeName { s =>
redirect(s"$s://www.$h$p", StatusCodes.MovedPermanently)
}
}
}
Edit: changed StatusCodes.SeeOther
to StatusCodes.MovedPermanently