diff options
| author | saturneric <[email protected]> | 2025-11-08 15:32:22 +0000 |
|---|---|---|
| committer | saturneric <[email protected]> | 2025-11-08 15:32:22 +0000 |
| commit | 46d5614be76c8ecc6295dfb5419510c8b33cfca3 (patch) | |
| tree | 6a4d5b51a294d5b62376bcf5cb674d8c7ff562ce | |
| parent | chore(submodule): update git submodule url (diff) | |
| download | cgit-46d5614be76c8ecc6295dfb5419510c8b33cfca3.tar.gz cgit-46d5614be76c8ecc6295dfb5419510c8b33cfca3.zip | |
feat(server): add URL redirect for uppercase paths
* Introduce Lua-based redirect to handle requests for uppercase
`GpgFrontend` URLs, ensuring they are rewritten to lowercase
equivalents for consistency.
* Enable the `mod_magnet` module in the server config, applying the
Lua redirect logic before other rewrites.
* Improve user experience by preventing duplicate route handling and
enforcing a unified URL structure.
| -rw-r--r-- | Dockerfile | 1 | ||||
| -rw-r--r-- | lighttpd.conf | 3 | ||||
| -rw-r--r-- | lua/redirect_lower_url.lua | 31 |
3 files changed, 34 insertions, 1 deletions
@@ -17,6 +17,7 @@ FROM alpine:latest AS runtime COPY --from=builder /var/www/htdocs/cgit /usr/share/webapps/cgit COPY ./filters /usr/lib/cgit/filters +COPY ./lua /usr/lib/cgit/lua RUN apk --no-cache add lighttpd python3 lua5.4 py3-markdown py3-pygments highlight diff --git a/lighttpd.conf b/lighttpd.conf index 4dc0b11..2caa18e 100644 --- a/lighttpd.conf +++ b/lighttpd.conf @@ -1,10 +1,11 @@ server.port = 80 server.document-root = "/usr/share/webapps/cgit/" server.indexfiles = ("cgit.cgi") -server.modules += ( "mod_access", "mod_alias", "mod_cgi", "mod_rewrite", "mod_proxy", "mod_accesslog" ) +server.modules += ( "mod_access", "mod_alias", "mod_cgi", "mod_rewrite", "mod_proxy", "mod_magnet" ) cgi.assign = ("cgit.cgi" => "") mimetype.assign = ( ".css" => "text/css" ) +magnet.attract-raw-url-to = ( "/usr/lib/cgit/lua/redirect_lower_url.lua" ) # log to stderr # accesslog.filename = "/dev/stderr" diff --git a/lua/redirect_lower_url.lua b/lua/redirect_lower_url.lua new file mode 100644 index 0000000..74ffc30 --- /dev/null +++ b/lua/redirect_lower_url.lua @@ -0,0 +1,31 @@ +-- /usr/lib/cgit/lua/debug_gpgfrontend.lua +local r = lighty.r +local a = r.req_attr + +-- Get the "original" path to avoid being affected by rewrites +local raw = a["uri.path-raw"] or a["uri.path"] or "/" +local orig = a["request.orig-uri"] or raw + +-- Match two entry points: +-- 1) /GpgFrontend/... +-- 2) /cgit.cgi/GpgFrontend/... (when the user accessed cgit.cgi directly) +local new_path + +if orig:match("^/GpgFrontend") then + new_path = orig:gsub("^/GpgFrontend", "/gpgfrontend") +elseif orig:match("^/cgit%.cgi/GpgFrontend") then + -- Convert /cgit.cgi/GpgFrontend/... to /gpgfrontend/... so rewrite adds /cgit.cgi only once + new_path = orig:gsub("^/cgit%.cgi/GpgFrontend", "/gpgfrontend") +end + +if new_path then + local q = a["uri.query"] + if q and #q > 0 and not new_path:find("%?") then + new_path = new_path .. "?" .. q + end + r.resp_header["Location"] = new_path + return 301 +end + +r.resp_header["X-Magnet-Probed"] = "1" +return 0
\ No newline at end of file |
