英文:
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/
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论