1

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    
</ifModule>"

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

2

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.

| improve this answer | |
  • thank bro.I did it – trung Jun 5 at 14:05
  • @trung If this answered your question then please mark it as "accepted" by clicking the tick/checkmark next to the answer (below the voting arrows) to help other readers. Once you have 15 rep you can also upvote answers that you find helpful. Thanks, much appreciated. :) – MrWhite Jun 5 at 21:25

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