Convert htacces to Nginx

Asked

Viewed 154 times

1

Good afternoon I’m migrating an Apache server to Nginx and I have a project with some rules on . htaccess that I don’t know how to convert to Nginx

are they:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule .* http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^(.*)/*sitemap.xml$ app.php?path=sitemap.xml [L]

RewriteCond %{REQUEST_URI} .(jpg|jpeg|png|gif)
RewriteCond %{HTTPS}s ^on(s)|

RewriteRule ^imagem/([/a-zA-Z0-9._-]+)$ http%1://outrodominio.com.br/up$

RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|css|js|zip|log|eot|ttf|woff|svg$
RewriteRule ^(.*)$ app.php?path=$1 [QSA,L]

I need help creating these rules in Nginx

1 answer

0

See if it helps:

# non-www to www
server {
  listen       80;
  listen       443 ssl;
  server_name  seudominio.com.br;

  return 301 $server_protocol://www.$server_name$request_uri;
}

server {
  listen       80;
  listen       443 ssl;
  server_name  www.seudominio.com.br;

  location / {

    if (-f $request_filename) {
      break;
    }

    if (-d $request_filename) {
      break;
    }

    rewrite ^(.+)$ /app.php?path=$1 last;
  }

  location /imagem/ {

    rewrite ^(.+)$ $server_protocol://outrodominio.com.br/up$1 last;
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.