不允许以html结尾跳转,拦截以 .html 结尾的url 开启匹配后缀

采用.html结尾的页面,更加容易被搜索引擎收录,提高网站的曝光率.

案例:

bVcHweF

bVcHwgi

bVcHweT

bVcHweI

希望通过*/index.html 访问的是index.jsp而不是真的index.html

那就需要拦截以 .html 结尾的url 跳转到index.jspimport org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;

import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //等同于web.xml配置文件

public class MvcConfigurer implements WebMvcConfigurer{

//开启匹配后缀型配置

@Override

public void configurePathMatch(PathMatchConfigurer configurer) {

//开启匹配后缀型配置 .html

configurer.setUseSuffixPatternMatch(true);

}

}

配置corspackage com.jt.config;

import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.CorsRegistry;

import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //标识我是一个配置类

public class CorsConfig implements WebMvcConfigurer {

//在后端 配置cors允许访问的策略

@Override

public void addCorsMappings(CorsRegistry registry) {

registry.addMapping("/**")

.allowedMethods("GET","POST") //定义允许跨域的请求类型

.allowedOrigins("*") //任意网址都可以访问

.allowCredentials(true) //是否允许携带cookie

.maxAge(1800); //设定请求长链接超时时间.

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值