Nginx Redirect Recommended Way (nginx_vhost.conf.master)

Discussion in 'Installation/Configuration' started by OptimBro, Apr 19, 2020.

  1. OptimBro

    OptimBro Member

    Hi Team

    Can we create redirection like the official method: Like this for http to https version?

    This is the recommended method.

    server {
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
    }
    server {
    server_name www.example.com;
    ....
    }

    Is it possible to do something like this by modifying nginx_vhost.conf.master?

    Code:
     
    <tmpl_if name='seo_redirect_enabled'>
            if ($http_host <tmpl_var name='seo_redirect_operator'> "<tmpl_var name='seo_redirect_origin_domain'>") {
                rewrite ^ $scheme://<tmpl_var name='seo_redirect_target_domain'>$request_uri? permanent;
            }
    </tmpl_if>
    
    Thanks
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, that should be possible. Remove the current part and add your code snippet outside of the server {} block. But I guess you will not notice any measurable difference unless you have millions of daily visitors in that site.
     

Share This Page