Redirecting to an internal URL seems to be possible by using the redirect() method in the controller.
public static Result index() {
return redirect(routes.Application.tasks());
}
However I want to redirect to an external URL in the controller. redirect(String) method accepts only internal URLs as parameter.
What I require is Play framework equivalent of standard Java servlet redirect i.e.
request.sendRedirect(String url)
The sendRedirect() method of HttpServletResponse interface can be used to redirect response to another resource, it may be servlet, jsp or html file. It accepts relative as well as absolute URL. It works at client side because it uses the url bar of the browser to make another request.
How to Redirect to Another Page in HTML. To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.
URL redirection is forwarding a user from one page to another page. There are basically two types of redirection:- Internal Redirection: Forwarding to internal pages. External Redirection: Forwarding to external pages (Other domains).
In Javascript, window.location function is used to redirect to a URL. JavaScript codes for redirecting to a URL: Code #1: <!DOCTYPE html>. <html>. <head>. <title>Redirect url in Javascript</title>. </head>. <body>.
Redirecting to an external URL in Laravel is quite straight forward but sometimes it might be hard for new Laravel developers that have not explored. To redirect the user to and external URL you can call the "away" function that's available after chaining the redirect () function.
Let’s say you want to redirect users to an external URL when they make an API request. How to do this in Spring Boot? There are two ways you can do this. Two using RedirectView object. STEP1: Create a REST Controller which returns Void Response Entity STEP2: Build a response entity with FOUND HttpStatus (302 code) and send the URL along with it
This is maybe the easiest and fastest method. Firstly, access your cPanel control panel. Scroll down and find the Domains – Redirects icon, as shown in the photo. Then, click on it. Then, we will explain how to configure the URL redirect in this screen.
Sometimes simplest solution just... works:
return redirect("http://stackoverflow.com/questions/10962694");
It's also worth to use other availabe redirects such as
seeOther(String url)
movedPermanently(String url)
temporaryRedirect(String url)
etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With