[英]JSF - ignore case in URLs (OCPSoft)
有沒有辦法在 OCPSoft 重寫中定義重寫規則,而不是定義多個規則,因為任何字符都可以是小寫或大寫?
cb.addRule(Join.path('/Test').to("/test.xhtml"));
cb.addRule(Join.path('/test').to("/test.xhtml"));
就像是:
boolean ignoreCase = true;
cb.addRule(Join.path('/Test', ignoreCase).to("/test.xhtml"));
背景:
記錄我們的 404 錯誤時,我遇到了很多使用小寫 URL 的請求。
是的。 絕對地。
最簡單的方法可能是使用帶有正則表達式.matches()
約束的參數:
cb.addRule(
Join.path('/{path}').to("/test.xhtml"))
.where("path")
.matches("(?i)test"); // <-- your path regex pattern goes here
您還可以將Resource
或Filesystem
條件與自定義轉換一起使用,以使其成為更全局的規則:
public class Lowercase implements Transposition<String>
{
@Override
public String transpose(Rewrite event, EvaluationContext context, String value)
{
return value.toLowerCase();
}
}
然后...
.addRule(Join.path("/{path}").to("/{path}.xhtml"))
.when(Resource.exists("{path}.xhtml"))
.where("path")
.matches("[a-zA-Z]+")
.transposedBy(new Lowercase())
這當然假設您的 xhtml 文件都使用小寫命名方案。
您可以創建自己的自定義.when()
條件來定位最可能的匹配項,然后在轉置中替換{path}
的“找到/正確”值,如果您想要 go 更遠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.