Generates 301 redirect from to

  # Mojolicious
  $app->plugin('RedirectHost', host => '');
  # Mojolicious::Lite
  plugin RedirectHost => { host => '' };

All requests with a Host header that is not equal to the host option will be redirected to the main host (and to the same port, as it was in original request) Don't forget about the port (don't expect something great from       =>  =>

You can point as many domains to your App by DNS, as you want. It doesn't matter, all of them will become a mirror. An equivalent apache .htaccess file looks like

        RewriteCond %{HTTP_HOST}   !^
        RewriteRule  ^(.*)    $1 [R=301,L]

It would be better if you'll be using per mode config files (your_app.production.conf etc). This would make possible to redirect only in production enviropment (but do nothing while coding your app)

Look at the `examples` directory of this distribution for a full application example



Main domain. All requests to the mirrors will be redirected to the host (domain) This option is required. Without it plugin do nothing


  $app->plugin('RedirectHost', host => '', code => 302);

Type of redirection. Default 301 (Moved Permanently)

er (except /robots.txt)

  $app->plugin('RedirectHost', host => '', er => 1);

If true, requests like /robots.txt will not be redirected but rendered. That's for Yandex search engine. If you want to change a domain but worry about yandex TIC, it's recomended to make it possible for Yandex to read your robots.txt with new Host directive. If so, that's exactly what you're looking for


If silent is true, doesn't write messages to the error log even if "host" is missing. Default value is false

You can configure plugin in a production config file and define silent in a development config.

        # app.production.conf
        # redirect_host => {host => ''},

        # app.development.conf: 
        # redirect_host => {silent => 1},


You can pass options to the plugin with the help of your config. Use redirect_host key.

  $app->config(redirect_host => {host => ''});

TIP: use per mode config files (yourapp.production.conf) to pass parameters to the plugin to avoid redirection during development process



Register. "register" in Mojolicious::Plugin