HttpsRedirect
The HttpsRedirect plugin redirects all HTTP requests to the HTTPS counterpart before processing the call. By default, a resource returns 301 Moved Permanently, but it can be configured to be 302 Found.
Add dependencies
To use HttpsRedirect, add the ktor-server-http-redirect artifact to your build script:
Install HttpsRedirect
To install the HttpsRedirect plugin to your application, pass it to the install function in the specified module. The following examples show how to install HttpsRedirect:
In an
embeddedServer()function call.In an explicitly defined
module()extension function on theApplicationclass.
The code above installs the HttpsRedirect plugin with the default configuration.
Configure HttpsRedirect
The code snippet below shows how to configure the desired HTTPS port and return 301 Moved Permanently for the requested resource:
You can find the full example here: ssl-engine-main-redirect.