URL正则表达式,不包括多个路径。

huangapple go评论74阅读模式
英文:

URL regex without several paths

问题

我有WebMvcConfigurer:

@Configuration
public class MyConfiguration implements WebMvcConfigurer {
    @Override
    public void addViewControllers (ViewControllerRegistry registry) {
        registry.addViewController("/{path:(?!api|res).*}")
            .setViewName("forward:/");
    }
}

我需要将所有请求重定向到index.html,除了路径/api/...和/res/...
无法创建适当的正则表达式,我将不胜感激您的帮助。

英文:

I have the WebMvcConfigurer:

@Configuration
public class MyConfiguration implements WebMvcConfigurer {
    @Override
    public void addViewControllers (ViewControllerRegistry registry) {
        registry.addViewController("/{path:(?!api|res).*}")
            .setViewName("forward:/");
    }
}

I need to redirect every request to index.html except paths /api/... and /res/...
Can not create appropriate regex, I'd appreciate your help.

答案1

得分: 0

This Regex matches if the string doesn't start with /path/ or /res/. (这个正则表达式匹配字符串不以/path//res/开头。)

英文:
^(?!(\/path\/+|\/res\/+)).*$

This Regex matches if the string doesn't start with /path/ or /res/.

huangapple
  • 本文由 发表于 2020年8月12日 21:28:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/63377576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定