在我的静态Web应用程序中,如果我从IntelliJ IDEA中打开index.html
,则可以从
http:// localhost:port / {项目名称} / {文件夹名称} /index.html
是否可以将此路径配置为类似这样的格式?
http:// localhost:port / {custom-folder} /index.html
1.在下面添加Maven依赖项,或将urlrewritefilter-4.0.3.jar直接添加到您的WEB-INF / lib目录中。
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.3</version>
</dependency>
2.将以下内容添加到您的WEB-INF/web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3.将urlrewrite.xml
添加到您的WEB-INF
目录中。 ( src/main/webapp/WEB-INF/
对于Maven用户)
<?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>/{custom-folder}/index.html</from>
<to type="redirect">/{project-name}/{folder-name}/index.html</to>
</rule>
</urlrewrite>
4.重新启动,重新部署应用程序
您可以访问http://127.0.0.1:8080/rewrite-status
(或本地Web应用程序的任何地址和上下文)以查看输出(请注意:此页面只能在localhost上查看)。
尝试http://localhost:port/{project-name}/{folder-name}/index.html
参考: http : //urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html