我希望每当用户在地址栏中输入uri时,我的pretty-config.xml文件中没有映射到404错误。 我的漂亮配置看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces>
<url-mapping id="landing">
<pattern value="/" />
<view-id value="/faces/index.xhtml" />
</url-mapping>
<url-mapping id="login">
<pattern value="/login" />
<view-id value="/faces/login.xhtml" />
</url-mapping>
</pretty-config>
例如,当用户输入myapp.com/faces/login.xhtml应用程序时,应该返回404错误。怎么做?
答案 0 :(得分:3)
我建议您使用重写(https://www.ocpsoft.org/rewrite)。它已经包含在你的PrettyFaces项目中:
package com.example;
@RewriteConfiguration
public class ExampleConfigurationProvider extends HttpConfigurationProvider
{
@Override
public int priority()
{
return 10000000; // Very large priority # should occur last.
}
@Override
public Configuration getConfiguration(final ServletContext context)
{
return ConfigurationBuilder.begin()
.addRule()
.when(
// filter inbound requests only
Direction.isInbound()
// match all paths
.and(Path.matches("/{p}"))
// only catch requests if they were not already internally forwarded by another rule
.and(Not.any(DispatchType.isForward()))
)
// Show the 404 page.
.perform(Forward.to("/404"))
// Allow "p" to match any URL path
.where("p").matches(".*");
}
}