Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to external URL in Play framework 2.0 (Java)

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)
like image 609
manish_s Avatar asked Jun 09 '12 16:06

manish_s


People also ask

How do I redirect a URL in Java?

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 do I redirect a URL to another user?

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.

What is external redirect?

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).

How to redirect URL in JavaScript?

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>.

How to redirect to an external URL in Laravel?

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.

How to redirect a user to an external URL in Spring Boot?

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

How to configure URL redirects in cPanel?

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.


1 Answers

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

like image 104
biesior Avatar answered Sep 21 '22 15:09

biesior