Created
July 21, 2018 14:19
-
-
Save samritbk/1ab13d16261abe73ec26b790ee8769bf to your computer and use it in GitHub Desktop.
Remove / in Spark Java (Allow with / and without /)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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