3

I'm using Cheyenne v0.9 and would like to serve static HTML files as text/html, but I don't want the URLs to contain the .html extension. Is there a way to do this without using CGI or some other dynamic processor?

For example:

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

To be reached using:

http://example.org/about

The Apache equivalent 'ReWrite' would be something like:

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]
rgchris
  • 3,698
  • 19
  • 19
  • Not exactly what you want but you could do that by using on-status-code [404 rewrite.rsp] config parameter. And inside rewrite.rsp just forward the request to *.html if file exists or show your 404 page if not. – endo64 Oct 29 '14 at 09:52
  • @endo64 Aye, that's a bit of a hack. Cheyenne should (not that Apache is any better) have a way of mapping a canonical url to a static resource, ideally tied to the 'Accept' header... – rgchris Oct 29 '14 at 16:41

1 Answers1

5

you can build a very simple mod which does this...

save the following as cheyenne/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
    ]
]

then add your module within your httpd.cfg like so :

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
]

restart cheyenne and voila!

If you look at the source for other mods, you can VERY easily setup a keyword for use in the httpd.cfg file in order to setup the auto-ext variable within the mod.

moliad
  • 1,503
  • 8
  • 13
  • To clarify (and I should've put this in my question), if there is no HTML file associated with a given URL, will it still pass through to the regular 404 handler? – rgchris Oct 30 '14 at 23:14
  • Be worth exploring how to make this work in conjunction with the Accept header also... – rgchris Oct 30 '14 at 23:16
  • yes it would generate a 404 handler. all we do is change the target (server side resource) the url refers to. – moliad Oct 31 '14 at 00:56