Redirect

HTTPS Redirect

HTTPS redirect middleware redirects http requests to https.
For example, http://labstack.com will be redirected to https://labstack.com.

Usage

  1. e := echo.New()
  2. e.Pre(middleware.HTTPSRedirect())

HTTPS WWW Redirect

HTTPS WWW redirect redirects http requests to www https.
For example, http://labstack.com will be redirected to https://www.labstack.com.

Usage

  1. e := echo.New()
  2. e.Pre(middleware.HTTPSWWWRedirect())

HTTPS NonWWW Redirect

HTTPS NonWWW redirect redirects http requests to https non www.
For example, http://www.labstack.com will be redirect to https://labstack.com.

Usage

  1. e := echo.New()
  2. e.Pre(middleware.HTTPSNonWWWRedirect())

WWW Redirect

WWW redirect redirects non www requests to www.

For example, http://labstack.com will be redirected to http://www.labstack.com.

Usage

  1. e := echo.New()
  2. e.Pre(middleware.WWWRedirect())

NonWWW Redirect

NonWWW redirect redirects www requests to non www.
For example, http://www.labstack.com will be redirected to http://labstack.com.

Usage

  1. e := echo.New()
  2. e.Pre(middleware.NonWWWRedirect())

Custom Configuration

Usage

  1. e := echo.New()
  2. e.Use(middleware.HTTPSRedirectWithConfig(middleware.RedirectConfig{
  3. Code: http.StatusTemporaryRedirect,
  4. }))

Example above will redirect the request HTTP to HTTPS with status code 307 - StatusTemporaryRedirect.

Configuration

  1. RedirectConfig struct {
  2. // Skipper defines a function to skip middleware.
  3. Skipper Skipper
  4. // Status code to be used when redirecting the request.
  5. // Optional. Default value http.StatusMovedPermanently.
  6. Code int `json:"code"`
  7. }

Default Configuration

  1. DefaultRedirectConfig = RedirectConfig{
  2. Skipper: DefaultSkipper,
  3. Code: http.StatusMovedPermanently,
  4. }