Skip to content

Instantly share code, notes, and snippets.

@samritbk
Created July 21, 2018 14:19
Show Gist options
  • Save samritbk/1ab13d16261abe73ec26b790ee8769bf to your computer and use it in GitHub Desktop.
Save samritbk/1ab13d16261abe73ec26b790ee8769bf to your computer and use it in GitHub Desktop.
Remove / in Spark Java (Allow with / and without /)
Spark.before((req, res) -> {
String path = req.pathInfo();
if (path.endsWith("/") && path.length() != 1) // length prevents redirect on homepage http://example.com/ <--
res.redirect(path.substring(0, path.length() - 1));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment