重写 nginx url 具体位置 url 为 PHP

Rewrite nginx url specific location url with PHP

我正在尝试将位置重写为 https。

但是我只想在这个特定位置执行此操作:http://test.org/forums/dfjk34dkk25cm369aa135cs56v34/

我只想将该目录中的 php 文件重定向到 https。

我目前的尝试没有成功。我做错了什么?

location ~ /forums/dfjk34dkk25cm369aa135cs56v34\.php(/|$) {

    return 301 https://$host$request_uri;

}

这成功了。

location ~ ^/forums/dfjk34dkk25cm369aa135cs56v34/.*php(/|$) {
  return 301 https://$host$request_uri;
}