Home » Php » nginx – Extensionless PHP pages gets cached and caused page to download

nginx – Extensionless PHP pages gets cached and caused page to download

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a core PHP based website, inorder to have clean urls without .php extensions in the URL I have made use of nginx config to serve the PHP as extension less.

But after fewdays I realised that the pages are now getting downloaded instead of execution , although the same page loads fine in INCOGNITO mode alone.

So I assume it has to do with some caching issue with the PHP page in browser side. Should I disable all cache in website or is there any workaround this issue.

nginx default conf

location / {
    try_files $uri $uri.html $uri/ @extensionless-php;
    index index.html index.htm index.php;
}

location ~ \.php$ {
    try_files $uri =404;
}

location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
}

How to&Answers: