How to redirect URLs with trailing slash to the corresponding ones without it?

前端 未结 7 1661
遥遥无期
遥遥无期 2020-12-05 10:12

Spring MVC (3.0) considers URLs with and without trailing slashes as the same URL.

For example:

http://www.example.org/data/something = http:

7条回答
  •  青春惊慌失措
    2020-12-05 10:55

    I agree with @Brian Clozel: I don't think is a good idea to do what you want. So, why you need it?

    Anyway, I think the simplest solution is to write a custom javax.servlet.Filter. So, no Spring dependency. If the request URL ends with slash you just have to redirect to the same url without it. But caution:

    • All parameters (GET and POST) must be added as GET parameters. Are you sure that your application is method agnostic?

    • You can have some problems with encoding. In the filter you can encode POST parameters to the required encoding. But the default encoding for GET parameters is not configured in your application. Is configured in server.xml (if Tomcat) and default value is ISO-8859-1.

    Good luck!

提交回复
热议问题