2013-02-13 83 views
4

如何設置Jetty只將特定父路徑轉發到目錄?例如,當用戶請求:localhost /它應該去localhost/CorrectDirectory。任何請求,如localhost/AnotherDirectory是否正確?Jetty將特定請求轉發到只有一個路徑

RewriteHandler gives的文檔:

<Set name="handler"> 
    <New id="Handlers" class="org.mortbay.jetty.handler.RewriteHandler"> 
    <Set name="rewriteRequestURI">false</Set> 
    <Set name="rewritePathInfo">false</Set> 
    <Set name="originalPathAttribute">requestedPath</Set> 
    <Call name="addRewriteRule"><Arg>/other/*</Arg><Arg>/test</Arg></Call> 
    <Call name="addRewriteRule"><Arg>/test/*</Arg><Arg></Arg></Call> 
    <Call name="addRewriteRule"><Arg>/*</Arg><Arg>/test</Arg></Call> 
    <Set name="handler"> 

從外觀上來看,如果我試圖把在本地主機重寫規則/我不得不每一個子目錄,以防止直接從名字說localhost/DirectoryTwo到localhost/CorrectDirectory/DirectoryTwo(這將是不正確的)。

回答

0

我不知道如果我得到你的問題的權利,我認爲它是這樣的:

我想重定向「/」,但只有「/」而不是「/成才」爲「/ somedestination」

看一看這個答案: https://stackoverflow.com/a/25405898/3489108

您可以通過使用RewriteRegexRule達到期望的結果。正則表達式「^/$」匹配字符串(^)的開頭,確切路徑(/)和字符串結尾($)。這確保了只有確切的路徑匹配。

我正在使用jetty 9 embedded並在代碼中設置我的重定向,因此我不禁要搞清楚,您如何設置「配置方式」。

相關問題