2014-10-27 40 views
3

我使用的是Cheyenne v0.9,並希望爲靜態HTML文件提供text/html,但我不希望URL包含.html擴展名。有沒有辦法做到這一點,而不使用CGI或其他動態處理器?如何從Cheyenne的靜態HTML文件的URL中取消.html?

例如:

http://example.org/about 

阿帕奇相當於 '改寫' 將是這樣的:

RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L] 
+0

不完全是你想要的,但你可以通過使用on-status-code [404 rewrite.rsp]配置參數來實現。並且在rewrite.rsp裏面,如果文件存在,只是將請求轉發到* .html,否則顯示你的404頁面。 – endo64 2014-10-29 09:52:22

+0

@ endo64是的,這有點破解。 Cheyenne應該(不是說Apache更好)有一種將規範URL映射到靜態資源的方式,理想情況下與'Accept'頭部綁定... – rgchris 2014-10-29 16:41:48

回答

5

你可以建立一個非常簡單的

/path/to/example.org/web-root/about.html 

要使用達到mod這是做什麼的...

以下內容作爲夏延/ MODS/MOD-AUTO-ext.r

REBOL [] 

install-HTTPd-extension [ 
    name: 'mod-auto-ext 

    order: [url-translate first] 

    auto-ext: '.html ; use whatever automatic extension you want! 

    url-translate: func [req /local cfg domain ext][ 
     unless req/in/ext [ 
      req/in/ext: auto-ext 
      append req/in/target req/in/ext 
     ] 

     ; allow other mods to play with url (changing target path for example) 
     return none 
    ] 
] 

然後在您httpd.cfg添加模塊,像這樣:

modules [ 
    auto-ext ;<----- put it as first item in list, whatever mods you are using. 

    userdir 
    internal 
    extapp  
    static 
    upload 
    expire 
    action 
    ;fastcgi 
    rsp 
    ssi 
    alias 
    socket 
] 

重啓夏安瞧!

如果你看看其他mods的源碼,你可以很容易地設置一個關鍵字在httpd.cfg文件中使用,以便在mod中設置auto-ext變量。

+0

爲了澄清(我應該把它放在我的問題中),如果沒有與給定URL關聯的HTML文件,它是否仍會傳遞給常規404處理程序? – rgchris 2014-10-30 23:14:28

+0

值得探討如何使這個工作與Accept標頭一起也... – rgchris 2014-10-30 23:16:58

+0

是的,它會產生一個404處理程序。我們所做的只是更改URL指向的目標(服務器端資源)。 – moliad 2014-10-31 00:56:36