I'm migrating from Apache to Nginx server and trying to figure out how to replace my .htaccess
with nginx config.
In my rewrite I want to enable pretty links and need the server to check if the first part is not a file then redirect to index.php
otherwise redirect to that file.
Example:
I have two PHP files in the root directory: index.php
and files.php
.
https://example.com/token/login ---> index.php/token/login
https://example.com/index.php/token/login ---> index.php/token/login //same as above
https://example.com/files.php/token/login ---> files.php/token/login
My current /default file is
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name vpn.simpleinformatics.com www.vpn.simpleinformatics.com;
return 301 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-vpn.simpleinformatics.com.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name vpn.simpleinformatics.com;
location / {
# try_files $uri $uri/ =404;
# try_files $uri $uri/ /index.php;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
location /phpmyadmin {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
}
}
This redirects all requests to index.php
, even files.php/etc..
requests :(.
So how can I tell nginx to check if the first part of URI is a file, then do the redirect to that file.