【发布时间】:2015-02-05 09:04:40
【问题描述】:
我有一个应用程序在 apache 实例后面的 tomcat 中运行。来自 apache 的请求是通过 mod_rewrite 代理的,因为这可以在 .htaccess 中进行配置,而我无权访问 vhost-configuration(甚至没有安装 mod_jk)。
.htaccess 如下所示:
RewriteRule ^/?my-app/(.*)$ http://localhost:8080/my-app/$1 [P]
Thymeleaf 很好地将上下文名称附加到所有 URL,并通过 HTML 生成相对名称,例如 /my-app/relative/path(因此没有 http://hostname-part),它们在此设置中完美运行。
不幸的是,一旦我使用 Spring MVC 重定向某些东西......
@RequestMapping("/redirect-to-relative-path")
public String redirect() {
return "redirect:/relative/path";
}
...用户被重定向到http://localhost:8080/my-app/relative/path 而不仅仅是/my-app/relative/path,这对外部用户不起作用。
Spring Security 还将尚未授权的用户重定向到 http://localhost:8080/my-app/login 而不仅仅是 /my-app/login。
我知道我可以使用完整的 URL 来重定向,但这应该是动态的。
使框架重定向到相对 URL 而不是附加主机名的最佳 (spring-boot-) 方法是什么? (...基本上就像 Thymeleaf 正在做的那样)
【问题讨论】:
标签: spring-security spring-boot thymeleaf