基于位置的正则表达式在Nginx中不起作用

时间:2020-05-18 18:20:06

标签: nginx url-rewriting

我希望这个基于位置的正则表达式可以与https://example.com/core/uploads/cache/fvm/1589747971/out/header-d0eb884c.min.css之类的网址一起使用,但是由于某种原因,它无法正常工作,在网上寻找各种正则表达式测试器后,我仍然无法弄清楚。

location ~* ^/core/(modules|uploads|assets)/(.*) {
    try_files /wp-content/plugins/$2 /wp-content/uploads/$2 /wp-content/themes/$2 =403;
    log_not_found off;
    access_log off;
  }

我还尝试过如下所示的url重写,但仍然很不幸:

location @hmwp {
  rewrite ^/core/modules/(.*) /wp-content/plugins/$2 last;
  rewrite ^/core/assets/(.*) /wp-content/themes/$2 last;
  rewrite ^/storage/(.*) /wp-content/uploads/$2 last;
  rewrite ^/core/(.*) /wp-content/$2 last;
  rewrite ^/lib/(.*) /wp-includes/$2 last;
  return 404;
}

0 个答案:

没有答案