Recently, I am trying to migrate from apache to nginx, while I am new to nginx, I was trying to re-construct my .htaccess. However, I got everything working except 1 main rule.
Current .htaccess configuration:
RewriteBase /
RewriteRule ^home$ index.php
RewriteRule ^file/? do.php?id= [QSA]
RewriteCond %{QUERY_STRING} ^(.*)id(.*)$
RewriteRule ^img/?([0-9]*)$ do.php?%1img%2
What I can notice on apache using above configuration, is that when browse: https://www.example.com/img?id=xxx (xxx is any image ID on website), it will auto redirect me to the photo using original Re-written URL (https://www.example.com/do.php?img=xxx)
While in Nginx, I used this configuration:
rewrite ^/home$ /index.php ;
rewrite ^/file/? /do.php?id= ;
if ($args ~ "^(.*)id(.*)$"){
set $rule_00 2;
set $bref_00_0 $1;
set $bref_00_1 $2;
}
if ($rule_00 = "2"){
rewrite ^/img/?([0-9]*)$ /do.php?${bref_00_0}img${bref_00_1} ;
}
But the issue I am facing, when I browse the image URL (https://www.example.com/img?id=xxx) it is not re-written to redirect me automatically, instead, it shows a download page.
Anyone can advise?