Hi,
I'm not sure if I'm posting this in the correct place as this is related to nginx configuration and not specifically PHP scripts. If I am posting this in the wrong section, please let me know and I will post it in the correct location (unless a Mod is able to move threads?).
I'm configuring nginx on my server and I've got it mostly configured how I want. The last thing I need to do (for now) is remove ".php" from the URL if someone goes there. I have done some research on this but can only find information on making nginx search for "file.php" if the URL ends in "file" which is not what I want.
The information I can find mostly refers to the try_files directive and says to do this:
try_files $uri $uri.php;
This is not what I want though. What this does is if "mysite.com/something" doesn't exist, try loading "mysite.com/something.php" without writing .php to the URL. What I want is if someone goes to "mysite.com/somthing.php" to redirect them to "mysite.com/something" preferably with a 301 redirect. Reversing the above would not do anything because the $uri
variable will contian ".php" if it's typed in to the address bar, making $uri.php
become file.php.php
.
This is very easy if I want to do it for specific files:
rewrite /page.php /page permanent;
The problem is that I want this to work for anything the end user may type.
I might be missing something very simple and trivial on how to do this. I doubt it's this simple, but does nginx have something similar to PHP's str_replace();
I could use to remove it?
I want this to happen even if the requested file exists. If more information is needed, let me know.