Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 1.94 KB

https-redirect.md

File metadata and controls

42 lines (28 loc) · 1.94 KB

Required dependencies: io.ktor:%artifact_name%

The %plugin_name% 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 {id="add_dependencies"}

Install %plugin_name% {id="install_plugin"}

The code above installs the %plugin_name% plugin with the default configuration.

When behind a reverse proxy, you need to install the ForwardedHeader or the XForwardedHeader plugin to detect HTTPS requests properly. If you get infinite redirect after installing one of these plugins, check out this FAQ entry for more details.

{type="note"}

Configure %plugin_name% {id="configure"}

The code snippet below shows how to configure the desired HTTPS port and return 301 Moved Permanently for the requested resource:

{src="snippets/ssl-engine-main-redirect/src/main/kotlin/com/example/Application.kt" include-lines="11-14"}

You can find the full example here: ssl-engine-main-redirect.