.php to non php redirect

Hi community!

First of all I have to praise Easy Engine - saves me heaps of time every day! I’ve seen this thread which is kind of what I’m looking for but more universal.

I have my own server where I host a few websites. It’s quite common for old websites to execute directly .php files. I’m happy to handle it from WP but this part of nginx prevents it:

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

I’ve been trying a few options securely but no luck so far.

What I’d be keen to have is a rewrite rule that if anyone enters somelink.com/about-us.php it would first try to see if there’s PHP file matching this URL and if not then redirect to somelink.com/about-us

Now that comes with risk of accessing directing plugin or WP files thus my question. Anyone had experience like that before?

hint if you need to solve it quickly currently I just create simple php file in WP main directory matching the file name with redirect in it for those pages - good workaround

What I’ve done when I had a similar need: created a file /var/www/domain.com/conf/nginx/redirects.conf containing something like:

location ~ ^/(.*)\.php$ { rewrite /$1; }

Notice my location statement includes the ^ sign, the slash and then “captures” the script name to $1.

Unfortunately I’m not sure this was my exactly working solution, because it demanded some try and error until I could find the exact formula; and my customer retired the site with the unusual permalinks (with the trailing .php).

I hope you can think of something useful now, or someone points another direction better than this, if possible.


I have this same issue. I need to redirect any empty .php files ( like www.domain.com/test/random.php) to wordpress so we can handle redirects within wordpress. However, right now all I get is a 404 from nginx. Any ideas?