Nginx rewrite rules not working

Discussion in 'Server Operation' started by Magiodev, Jan 15, 2019.

  1. Magiodev

    Magiodev New Member

    Hi guys, i'm trying to translate htaccess rules to Ngingx, using winginx.com/en/htaccess.

    I'm used to set nginx directives inside each website Settings > Redirects > Rewrite Rules.

    My actual nginx configuration file is:
    location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;​
    }​

    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 365d;​
    }location ~* \.(pdf)$ {
    expires 30d;​
    }​

    The rule I want to set is:
    Redirect 301 /vehiculos-nuevos.php https://valauto.es/vehiculos/vehiculos-nuevos/

    And it's translated to: (ISPConfig says invalid Rewrite Rule)
    location /vehiculos-nuevos.php {
    }​

    And i've also tried without location property, trying to set single lines: (Accepted by ISPconfig but error 404)
    rewrite '^/vehiculos-nuevos.php' '/vehiculos/vehiculos-nuevos/' permanent;​


    But I get error by ISPConfig or error 404 instead of the correct redirection.

    Thanks in advance for your help!
     
    Last edited: Jan 15, 2019
  2. manoaratefy

    manoaratefy New Member

    I think that the correct way to do this is the following:
    Code:
    rewrite ^/vehiculos-nuevos.php$ https://valauto.es/vehiculos/vehiculos-nuevos/ permanent;
     

Share This Page