I want to convert this htaccess code to nginx.

<ifModule mod_rewrite.c>    
RewriteEngine On
## Application Handler   
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ index.php?a=$1  [QSA,NC,L]    
## Error 404 ##
ErrorDocument 404 /index.php?a=404    

I use winginx to convert when I inserted the code into nginx, there is a problem downloading the file. Can anyone help me? thank you


The two RewriteCond statements perform the same function as the Nginx try_files directive. For example:

try_files $uri $uri/ /index.php?a=$uri;

However, the RewriteRule probably appends the original request without the leading /, so a more accurate translation might be:

location / {
    try_files $uri $uri/ @rewrite;
location @rewrite {
    rewrite ^/(.*)$ /index.php?a=$1;

See this document for details.

The error handler is translated to either of (depending on what status code you need):

error_page 404 /index.php?a=404;
error_page 404 = /index.php?a=404;

See this document for details.

  • thank bro.I did it – trung Jun 5 '20 at 14:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.