Vincent Decaux
Vincent Decaux

Reputation: 10714

RewriteRule to nginx conf

I got an .htaccess with :

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

I need to convert this to nginx conf, it's very simple but I don't find..

I tried :

server {
    server_name ****;
    root /path;

    index index.html index.php;
    listen 80;

    # set expiration of assets to MAX for caching
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        expires max;
        log_not_found off;
    }

    location / {
      if (!-e $request_filename){
        rewrite ^(.+)$ /index.php?url=$1 break;
      }
    }

    location ~* \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

But it downloads file instead of showing it. I don't get it ?

It works if I use :

http://example.com/index.php?url=login

But not with :

http://example.com/login

Upvotes: 0

Views: 49

Answers (1)

Vincent Decaux
Vincent Decaux

Reputation: 10714

Ok, it works using :

location / {
    try_files $uri $uri/ /index.php?url=$uri;
}   

Upvotes: 1

Related Questions