Always SSL and 302 redirect

194 views
Skip to first unread message

Vamsi Krishna Penumatsa

unread,
Nov 28, 2015, 2:39:00 AM11/28/15
to Google App Engine
Hello,

I have used security constraints section in appengine-web.xml to redirect all the http requests on my site to https. The redirect works flawlessly, however I have noticed that appengine is issuing a 302 redirect. I want the appengine to use a 301 redirect, for SEO purposes.

Is there any method/mechanism to make appengine redirect using 301 rather than 302.

Thank,
Vamsi

Adam

unread,
Nov 28, 2015, 5:09:42 PM11/28/15
to Google App Engine
This was discussed in an older public issue which was closed as it's implemented this way due to a design philosophy. However there is an easy workaround - you can issue a 301 redirect manually in your own servlet code if you detect the request URL is HTTP (first remove the security constraint to allow both HTTP and HTTPS by default):

if (!request.isSecure()) {
  response.setStatus(301);
  // Get original path from request....
  response.setHeader(“Location”, “https://” + originalPath);
}

Cheers,

Adam
Cloud Platform Support
Reply all
Reply to author
Forward
0 new messages