nginx try_files with custom location ^/([0-9]+)

qyzbxkaa  于 2024-01-06  发布在  Nginx
关注(0)|答案(1)|浏览(159)

我试图运行位置与相同的规则重写
nginx重写

  1. rewrite ^/([0-9]+)$ /post.php?id=$1 ;

字符串
不工作用

  1. location ~ ^/([0-9]+) {
  2. try_files /s.php-$1.txt /s.php?page=$1 ;
  3. root /home/XX/public_html;
  4. types {}
  5. default_type text/html;
  6. }


如果我添加任何像^/S([0-9]+)这样的单词,它会工作得很好。
但如果没有 S,此规则会损坏所有图像和其他URL

gc0ot86w

gc0ot86w1#

我花了好几年的时间试图修复它,但毫无希望
今天,我发现想法时,看到的方式404与自定义位置

  1. error_page 500 502 503 504 404 /custom.html;
  2. location = /custom.html {
  3. try_files /cachep/index.txt /index.php ;
  4. root /home/xxx/public_html;
  5. types {}
  6. default_type text/html;
  7. }

字符串
那又怎么样,如果重写工作正常
我们将以同样的方式使用它与位置

  1. rewrite ^/([0-9]+)$ /T$1 ;
  2. location ~ /T([0-9]+) {
  3. try_files /cachep/$1.html /post.php?id=$1 ;
  4. root /home/xxx/public_html;
  5. expires max;
  6. types {}
  7. default_type text/html;
  8. }


我用

  1. types {}
  2. default_type text/html;


使txt文件像html一样查看
我希望有一天任何一个搜索同样的问题找到它

展开查看全部

相关问题