当前位置: 首页 > Web前端 > HTML

拦截以.html结尾的URL并启用匹配后缀

时间:2023-04-03 00:39:40 HTML

以.html结尾的页面更容易被搜索引擎收录,增加网站的曝光率。案例:如果想通过*/index.html访问index.jsp而不是真正的index.html,需要拦截以.html结尾的url跳转到index.jspimportorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.PathMatchConfigurer;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration//相当于web.xml配置文件publicclassMvcConfigurerimplementsWebMvcConfigurer{//启用匹配后缀配置@OverridepublicvoidconfigurePathMatch(PathMatchConfigurerconfigurer){//启用匹配后缀配置.htmlconfigurer.setUseSuffixPatternMatch(true);}}配置corspackagecom.jt.config;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.CorsRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration//标识我是一个配置类publicclassCorsConfigimplementsWebMvcConfigurer{//在后端配置cors访问策略@OverridepublicvoidaddCorsMappings(CorsRegistryregistry){registry.addMapping("/**").allowedMethods("GET","POST")//定义允许跨域的请求类型。allowedOrigins("*")//可以访问任何URL。allowCredentials(true)//是否允许携带cookies.maxAge(1800);//设置请求长链接超时时间。}}