Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:19:20+00:00 2026-05-29T07:19:20+00:00

I want to enforce https routing for the login page only of my application.

  • 0

I want to enforce https routing for the login page only of my application.

Is it possible to do so with Play! without the use of a front end http server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:19:22+00:00Added an answer on May 29, 2026 at 7:19 am

    You can use an @Before interceptor to redirect every request, even if the user types http:// directly. Below is the code that I use (it works when running containerless play run, or when running behind a front end such as on Heroku).

    public class HttpsRequired extends Controller {
        /** Called before every request to ensure that HTTPS is used. */
        @Before
        public static void redirectToHttps() {
            //if it's not secure, but Heroku has already done the SSL processing then it might actually be secure after all
            if (!request.secure && request.headers.get("x-forwarded-proto") != null) {
                request.secure = request.headers.get("x-forwarded-proto").values.contains("https");
            }
    
            //redirect if it's not secure
            if (!request.secure) {
                String url = redirectHostHttps() + request.url;
                System.out.println("Redirecting to secure: " + url);
                redirect(url);
            }
        }
    
        /** Renames the host to be https://, handles both Heroku and local testing. */
        @Util
        public static String redirectHostHttps() {
            if (Play.id.equals("dev")) {
                String[] pieces = request.host.split(":");
                String httpsPort = (String) Play.configuration.get("https.port");
                return "https://" + pieces[0] + ":" + httpsPort; 
            } else {
                if (request.host.endsWith("domain.com")) {
                    return "https://secure.domain.com";
                } else {
                    return "https://" + request.host;
                }
            }
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have https for entire application. I decided to use this gem:
I want to have mixed https/http site. Moreover I want have redirects from https
In a (proper RMM level 3) RESTful HTTP API, I want to enforce the
I want to enforce that date-times that are entered fall between 9am and 5pm.
I want to enforce CHECK constraint on a date range such that all dates
I want to enforce on my code base immutable rule with following test [TestFixture]
I want to enforce single question mark at the and of the string. In
I've created few scopes for my ActiveRecord entity and I want to enforce user
I want to allow the user to edit by data by row, so only
I want to enforce (i.e. throw an error and fail) that whenever I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.