Nginx Subdomain rewrite

Discussion in 'ISPConfig 3 Priority Support' started by h4ni, Jan 19, 2016.

  1. h4ni

    h4ni New Member

    I use nginx in ispconfig 3 panel The vhost are like this
    Code:
    server {
        listen *:80;
    
    
        server_name domain.com www.domain.com sub.domain.com;
    
        root   /var/www/domain.com/web;
    
        if ($http_host = "sub.domain.com") {
            rewrite ^(?!/\b(ar|stats|error)\b)/(.*)$ /sub/$2 ;
    
        }
    
    
        index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
        rewrite ^/contactez-nous /contact.php break;
    
    
        error_page 400 /error/400.html;
        error_page 401 /error/401.html;
        error_page 403 /error/403.html;
        error_page 404 /error/404.html;
        error_page 405 /error/405.html;
        error_page 500 /error/500.html;
        error_page 502 /error/502.html;
        error_page 503 /error/503.html;
        recursive_error_pages on;
        location = /error/400.html { ...
    
    I want to add an rewrite rule in sub.domain.com

    I try this, but do not work

    Code:
    if ($http_host = "sub.domain.com") {
    rewrite ^(?!/\b(ar|stats|error)\b)/(.*)$ /sub/$2 ;
    
    rewrite ^/contactez-nous /contact.php break;
    }
    Does any one have an idea?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Any rror's in the log of the website?
     
  3. h4ni

    h4ni New Member

    I get this error, when i try to acces to http://sub.domain.com/contactez-nous
     
    Last edited: Jan 19, 2016
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Try to exchange the order of the rewrite lines to:

    rewrite ^/contactez-nous /contact.php break;
    rewrite ^(?!/\b(ar|stats|error)\b)/(.*)$ /sub/$2 ;
     
  5. h4ni

    h4ni New Member

    This work, thank you, but we must add /sub befor contact.php, like this

    rewrite ^/contactez-nous /sub/contact.php break;
    rewrite ^(?!/\b(ar|stats|error)\b)/(.*)$ /sub/$2 ;
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Ok. The reason is that the first rewrite has been processed already so probably this should work as well:

    rewrite ^(?!/\b(ar|stats|error)\b)/(.*)$ /sub/$2 ;
    rewrite ^/sub/contactez-nous /sub/contact.php break;

    But I would leave it in the reverse order.
     
    h4ni likes this.
  7. h4ni

    h4ni New Member

    Thank you
     

Share This Page