Java – use play 2.0 X for permanent redirection

I want to know how to play in the framework 2.0 X to permanently redirect the subdomain 301

Solution

Global object will allow you to intercept the request For obvious reasons, you should use get requests (i.e. for search engine optimization purposes), but others, such as post, put, etc., should be created correctly from the beginning of the view

On the other hand, if only some applications that serve common HTML pages for life and production consider using some HTTP servers in front of it - you can implement it through some rewriting rules

import play.GlobalSettings;
import play.mvc.Action;
import play.mvc.Http;
import play.mvc.Result;

import java.lang.reflect.Method;

public class Global extends GlobalSettings {

    @Override
    public Action onRequest(final Http.Request request,Method method) {
        if ("GET".equals(request.method()) && "www.example.com".equals(request.host())) {
            return new Action.Simple() {
                public Result call(Http.Context ctx) throws Throwable {
                    return movedPermanently("http://example.com" + request.path());
                }
            };
        }
        return super.onRequest(request,method);
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>