I\'ve tried so many different configurations to enable permanent redirection of any request ending with .php to redirect to itself without .php.
The issue is, I can\'t g
You're likely experiencing the issue with your browser having your prior 301 Moved Permanently
redirects in its cache, thus some of your newer code would not be having any effect.
Clear the cache, and try something like this:
index index.php;
if ($request_uri ~ ^/([^?]*?)(?:(?<=/)index(?:\.php)?|\.php)(\?.*)?$) { return 301 /$1$2; }
The above line supports stripping out not only index.php
, but also just index as you might have from your earlier question, as well as just .php
, yet it preserves the possible query string from $args
, too.
To avoid having support for stripping just index
, still supporting the rest of the features as above, use the following instead:
if ($request_uri ~ ^/([^?]*?)(?:(?<=/)index)?\.php(\?.*)?$) { return 301 /$1$2; }
P.S. The original explanation of this trick is here: nginx redirect loop, remove index.php from url.