I've created a simple php file to display info fetched from my MYSQL database. Right after that i use a rewrite rule in Nginx to make the link seo friendly and to mask the .php file that fetches it.
Ex: http://localhost/myfile.php?seo=how-to-install-linux
After rewrite rule the i can access it like:
http://localhost/how-to-install-linux
My rewrite rules are:
location / {
rewrite ^/([a-zA-Z0-9_$\-]+)$ /myfile.php?seo=$1 last;
rewrite ^/(.*)/$ /$1 permanent; <- just to block trailing slash
}
My problem is that i also want to block any direct access to my php file and i want only the seo friendly url to work.
location = /myfile.php {
deny all;
}
This rule blocks complete access to my php file, including through seo friendy url. Is there a way to make it work for the seo friendly version using NGINX? My other settings are:
location ~ \.php$ {
try_files $uri =404;
include fcgi.conf;
fastcgi_pass unix:/var/run/ajenti-v-php7.0-fcgi-drnou-php7.0-fcgi-0.sock;
}
I only use Nginx, no Apache installed.