简体   繁体   中英

Redirect to invalid URL e.g. an deeplink like 'my.app://'

I've built a spring-web-mvc service which delivers some basic pages using Thymeleaf. Now I've placed a button on one of the sites which should redirect the user (back) to an app by using the app deep link. The deep link schema looks like following: 'my.app://'

When pressing the button the underlying controller is invoked returning a string

@PostMapping("getBackToApp")
public String getBackToApp(@RequestParam final String myCoolAppLink) {
return "redirect:" + myCoolAppLink
}

The controller gets invoked and returns the corresponding string. I have thought that the user would get redirected "mycoolAppLink" (should be shown in the URL bar of the corresponding browser) but instead the "myCoolAppLink" gets attached to the current URL which for example looks like following:

http://localhost:9999/myApp/myPage/my.app://

instead of

my.app://

So it seems like that when the protocol is missing the redirect instruction gets appended to the current URL.

I also tried it using a GET controller, or performing a redirect instruction using the HttpServletRequest but neither of the approaches seem to work.

As the deep link of apps do not have a correct protocol (http / https) I wonder how to achieve this? Maybe I am getting something wrong but I thought sending a redirect back to the client with the specific URL should do the trick!

PS: I not tried it on a mobile device but I assume that it wouldn't work.

Thanks!

I believe you can use the RedirectView

@RequestMapping("/getBackToApp")
public RedirectView localRedirect() {
    RedirectView redirectView = new RedirectView();
    redirectView.setUrl("my.app://");
    return redirectView;
}

Although I have yet to try this with a "none" http url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM