2011-09-12 3 views
0

tomcat rewrite.xml 파일을 통해 java 응용 프로그램에 대한 url 규칙을 이미 정의했습니다. 우리는 URL http://example-laboratories.pt URL을 요청하지만 사용자가 http://example-laboratories.pt/pt을 요청하면 http://example-laboratories.pt/pt로 리디렉션해야 할 때tomcat에 대한 URL 다시 작성

<rule> 
    <condition name="host" operator="equal">example-laboratories.pt</condition> 
    <from>[^pt]/(.*)$</from> 
    <to type="redirect">http://example-laboratories.pt/pt/$1</to> 
</rule> 

이 작동합니다. 이제 위의 규칙은 http://example-laboratories.pt/pt/pt으로 리디렉션됩니다 (끝에 'pt'가 추가됨).

+1

난 당신이 내가 할 수있는 원 다시 이해 _quite_하지 않았다을 해결책을 제시하지는 않지만 정규 표현식 문제는 확실합니다. (그'from'은 당신이 기대하는 것과 일치하지 않습니다 ...) –

답변

0

나는 당신이 원하는 것을 정확히 모르겠지만, 당신이 당신의 정규 표현식에 오류가있는 것 같습니다 :

<from>[^pt]/(.*)$</from> 

이 실제로 'P'또는 't'를 제외하고 "모든 문자는 말한다 그 다음에 슬래시가오고 그 다음에는 0 개 이상이 나옵니다. "

나는 그것이 당신이 원하는 것이라고는 확신하지 않지만, 당신이하고 싶은 것과 같지 않습니다. 다른 URL 재 작성 도구를 사용하면 대부분 정규식을 피할 수 있습니다. (당신이 Tuckey를 사용하는 것 같습니다?)

당신이 사용 OCPsoft 재 작성 (http://ocpsoft.com/rewrite/) 예를 들어

수행 할 수 있습니다

ConfigurationBuilder.begin() 
.defineRule() 
.when(Domain.matches("example-laboratories.pt") 
    .and(Path.matches("/{1}/{2}") 
     .where("1").matches("(?!pt)[^/]+") 
     .where("2").matches(".*"))) 
.perform(Redirect.permanent(context.getContextPath() + "/pt/{2}"))