简体   繁体   English

如何使用Cheyenne从静态HTML文件的URL中抑制.html?

[英]How do you suppress .html from the URLs of static HTML files with Cheyenne?

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. 我正在使用Cheyenne v0.9并希望将静态HTML文件作为text/html ,但我不希望URL包含.html扩展名。 Is there a way to do this without using CGI or some other dynamic processor? 有没有办法在不使用CGI或其他动态处理器的情况下执行此操作?

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: Apache等效的'ReWrite'类似于:

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

you can build a very simple mod which does this... 你可以建立一个非常简单的mod来做到这一点......

save the following as cheyenne/mods/mod-auto-ext.r 将以下内容保存为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 : 然后在你的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
]

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. 如果您查看其他mod的源代码,您可以非常轻松地设置一个关键字,以便在httpd.cfg文件中使用,以便在mod中设置auto-ext变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从GitHub页面网站(Jekyll)的URL中删除文件扩展名,同时将我的HTML文件保存在一个文件夹中? - How do I remove file extensions from a URLs of a GitHub Pages site (Jekyll) while keeping my HTML files in one folder? 静态页面,URL末尾不使用“ .html” - Static pages without using at the end the “.html” at the URLs 使用重定向从URL中删除.html - Remove .html from URLs with a redirect 如何用最终重定向替换 HTML 中的所有 URL? - How do I replace all URLs in HTML with their final redirect? 如何从静态 html 网站页面中删除 .html - How can i remove .html from static html website pages 不以点 html/php 结尾的 URL 的 RewriteRule - RewriteRule for URLs that do not end with dot html/php 如何在nginx的WordPress网址中添加“ .html”? - How to add “.html” to wordpress urls in nginx? 如何使用查询字符串中的数据重写Azure图像URL - How do you rewrite Azure image URLs with data from the query string 如何使用正则表达式将所有请求路由到servlet *除*静态文件“ /(images|css|jsp|html)/.*” - How to use regex to route all requests to servlet *except* static files “/(images|css|jsp|html)/.*” 如何将.html附加到cakephp中的所有网址? - How can I append .html to all my URLs in cakephp?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM