springboot伪静态
在日常网站访问中,会把动态地址改造成伪静态地址。
例如: 访问新闻栏目 /col/1/,这是原有地址,如果这样访问,不利于搜索引擎检索收录,同时安全性也不是很好。
改造之后:
/col/1.html。
改造方法:
1.添加urlrewritefilter
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
2.配置bean

import java.io.IOException; import javax.servlet.FilterConfig;
import javax.servlet.ServletException; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.tuckey.web.filters.urlrewrite.Conf;
import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; @Configuration
public class UrlRewriteFilterConfig extends UrlRewriteFilter { private static final String URL_REWRITE = "classpath:/urlrewrite.xml"; // Inject the Resource from the given location
@Value(URL_REWRITE)
private Resource resource; // Override the loadUrlRewriter method, and write your own implementation
protected void loadUrlRewriter(FilterConfig filterConfig) throws ServletException {
try {
// Create a UrlRewrite Conf object with the injected resource
Conf conf = new Conf(filterConfig.getServletContext(), resource.getInputStream(), resource.getFilename(),
"@@traceability@@");
checkConf(conf);
} catch (IOException ex) {
throw new ServletException("Unable to load URL rewrite configuration file from " + URL_REWRITE, ex);
}
}
}

参考网址:http://blog.jdriven.com/2016/02/urlrewritefilter-load-configuration-with-spring-resourceloader/
3.配置urlrewrite.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"> <urlrewrite> <!-- 栏目首页 -->
<rule>
<from>^/col/(\w+)\.html$</from>
<to>/col/$1/</to>
</rule> <!-- 栏目列表页,注意html后面没有加$,因为后面还有若干参数 -->
<rule>
<from>^/col/list/(\w+)/(\w+)\.html</from>
<to>/col/list/$1/$2/</to>
</rule> <!-- 文章详情页 -->
<rule>
<from>^/art/(\w+)\.html$</from>
<to>/art/$1/</to>
</rule> <!-- 静态网页 -->
<rule>
<from>^/static/(\w+)\.html$</from>
<to>/static/$1/</to>
</rule> </urlrewrite>


配置说明请参考:http://blog.163.com/zhangmihuo_2007/blog/static/27011075201351433716225/
至此配置完毕,启动测试,注意看红框处,说明加载了urlwrite。

访问页面如下,成功了!

springboot伪静态的更多相关文章
- springboot中配置urlrewrite实现url伪静态强化网站seo
关于urlrewrite urlrewrite使用强大的自定义规则来使用用户更容易记住.搜索引擎更容易找到的URL(对于seo比较重要).通过使用规则模板.重写映射,Web管理员可以轻松地设置规则,根 ...
- 解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用
问题: Springboot启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ...
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
- Springboot搭建web项目
最近因为项目需要接触了springboot,然后被其快速零配置的特点惊呆了.关于springboot相关的介绍我就不赘述了,大家自行百度google. 一.pom配置 首先,建立一个maven项目,修 ...
- Java——搭建自己的RESTful API服务器(SpringBoot、Groovy)
这又是一篇JavaWeb相关的博客,内容涉及: SpringBoot:微框架,提供快速构建服务的功能 SpringMVC:Struts的替代者 MyBatis:数据库操作库 Groovy:能与Java ...
- 解决 SpringBoot 没有主清单属性
问题:SpringBoot打包成jar后运行提示没有主清单属性 解决:补全maven中的bulid信息 <plugin> <groupId>org.springframewor ...
- SpringBoot中yaml配置对象
转载请在页首注明作者与出处 一:前言 YAML可以代替传统的xx.properties文件,但是它支持声明map,数组,list,字符串,boolean值,数值,NULL,日期,基本满足开发过程中的所 ...
- springboot 学习资源推荐
springboot 是什么?对于构建生产就绪的Spring应用程序有一个看法. Spring Boot优先于配置的惯例,旨在让您尽快启动和运行.(这是springboot的官方介绍) 我们为什么要学 ...
- PHP如何实现网址伪静态
Apache的 mod_rewrite是比较强大的,在进行网站建设时,可以通过这个模块来实现伪静态. 主要步骤如下: 1.检测Apache是否开启mod_rewrite功能 可以通过php提供 ...
随机推荐
- OCP认证052考试,新加的考试题还有答案整理-23题
23.Which two are true about data dictionary and dynamic performance views (v$ views)? A) All databas ...
- 在Java中如何优雅地判空
判空灾难 作为搬砖党的一族们,我们对判空一定再熟悉不过了,不要跟我说你很少进行判空,除非你喜欢NullPointerException. 不过NullPointerException对于很多猿们来 ...
- 关于react的一些疑问点
参考转载:链接:http://www.jianshu.com/p/83bda9cd8c67 1.refs <input type="text" ref="input ...
- [转] HTTP状态码错误代码
一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 ...
- java内存模型(jMM)(二)
volatile关键字 volatile是一个类型修饰符(type specifier),就像大家更熟悉的const一样,它是被设计用来修饰被不同线程访问和修改的变量.volatile的作用是作为指令 ...
- 浅谈Ionic2
http://www.cnblogs.com/zhouming-web/p/6226323.html 前言: 不要用angular的语法去写angular2,有人说二者就像Java和JavaScrip ...
- Python处理json数据--世界国家维度数据
1.准备国家的json数据 将准备好的json数据放在指定的目录下,此处可以重这里下载 2.测试编写python脚本处理json提取字段值 #coding:utf8 import time, re, ...
- nginx下重写隐藏index.php文件
location / { root /项目目录/; index index.php; if (-f $request_filename/index.php){ rewrite (.*) $1/inde ...
- django执行过程
- 主流服务器虚拟化技术简单使用——Hyper-V(一)
Tips:因为博客园排版的原因,图片显示不清晰,可以放大网页查看清晰图片. 如果系统使用物理机,需要在BIOS里面开启Intel VT-x(或AMD-V),如果是VMware workstation, ...