How do I make Lighttpd resolve http://example.com/abcd to http://example.com/abcd.html

By default, it looks like lighttpd doesn’t resolve html files without the extension. I’m trying to setup quartz – https://quartz.jzhao.xyz/ and that has html files, but links are all without the htmls.

I’m trying to open http://example.com/abcd, which should open http://example.com/abcd.html (the html is present in the server) but it’s not resolving the html extension part, and is throwing a 404.

Also, I need this to happen for multiple URLs, and they’re all dynamic, so this won’t work for me: How do I use rewrite on Lighttpd?

So far, I used this config:

url.rewrite-repeat-if-not-file = ( "^(.*)/index.html$" => "$1.html", "" => "${url.path}/index.html" )

So, if there’s no matching file, it will add /index.html. If it has a /index.html (might have been added as part of the 2nd rule), then take up to before /index.html and add.html.

This doesn’t solve my problem either, because it will not throw 404 in case a file indeed doesn’t exist. It will instead find an infinite loop in the rules and reset connection.

This also doesn’t work for me

url.rewrite-repeat-if-not-file = ( "^(.*)/index.html$" => "$1.html", "(.*)/$" => "${url.path}/index.html" )

So, if there’s no matching file and the matcher ends with /, which it should if there’s no extension being passed from the client, it will add /index.html. If it has a /index.html (might have been added as part of the 2nd rule), then take upto before /index.html and add.html. This is working by throwing 404 for actually non-existent files. The .html is being added when passed without the extension but the file is there. And the index.html is being added when no extension is passed (browser should request for the url followed by a /, assuming folder).

Turns out my assumptions were incorrect. The server isn’t getting a / and thus the 2nd rule is not getting hit. Either way, this brings me back to square 1 where the .html is not being added.

Yes, many of your assumptions are incorrect, but kudos to you for testing those assumptions yourself to find that out.

A simplistic solution might be to rewrite any url without a ‘.ext’ to ‘.html’ using a negative lookahead regex pattern

url.rewrite-if-not-file = (  "(?!.[^/]*)$" => "${url.path}.html" )

but that may also rewrite other paths, e.g. if you serve directory listings.

A thorough solution is to use mod_magnet with a short custom lua script to test if the url with .html appended resolves to a file, and if so rewrite it, and if not, leave it alone.

Another solution is to a custom script as a target for mod_indexfile, e.g. index-file.names = ( "index.py" ) to do something similar in Python to what you can do with mod_magnet, but I personally prefer mod_magnet, which is much faster since it runs inside lighttpd.

Edit: adding mod_magnet example (Note: you need to replace /path/to/ with actual path)

lighttpd.conf

server.modules += ("mod_magnet")
magnet.attract-physical-path-to = ("/path/to/pretty-url-to-html.lua")

/path/to/pretty-url-to-html.lua

-- Check if path has an extension or exists in filesystem,
-- else check filesystem for path with ".html" appended.
local path = lighty.r.req_attr["physical.path"]
if (not string.match(path, "%.[^/]*$") and not lighty.c.stat(path)) then
  local st = lighty.c.stat(path .. ".html")
  if (st and st.is_file) then
    return st["http-response-send-file"]
  end
end

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật