title: Externally redirect URL in NGINX conf to add slashes and use php files
body: <p>I'm new in this site and new with NGINX, so be nice, please. I rencently switched to AWS Elasticbeanstalk and need help with NGINX configuration. I wanna do some redirection that I know and tested that works in apache2 with .htaccess but I'm not able to acomplish with NGINX.</p>
  <p>I want all my URL to end with trainling slash, check if $uri is a directory if so use index.php if not use last name as the name of the script as follows:</p>
  <p>I want that this URL:     uses this script:</p>
  <p>https://localhost/ -&gt; ./index.php</p>
  <p>https://localhost/page/ -&gt; ./page.php</p>
  <p>https://localhost/folder/page/ -&gt; ./folder/page.php</p>
  <p>https://localhost/folder/page/?param=foo -&gt; ./folder/page.php?param=foo</p>
  <p>I made it behave like this in apache2 with this config in .htaccess:</p>
  <pre><code># To externally redirect /dir/foo.php to /dir/foo
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
  RewriteRule ^ %1/ [R,L]
  
  # add a trailing slash   
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !/$
  RewriteRule . %{REQUEST_URI}/ [L,R=301]
  
  # To internally forward /dir/foo to /dir/foo.php
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^(.*?)/?$ $1.php [L]
  </code></pre>
  <p>How can I translate this .htaccess into NGINX config file?</p>
  <p>Thanks in advance.</p>