Feature #1259
closedmod_autoext - Apache-like support for automatically adding extensions
Description
Pretty URLs are very common these days - using /thread/123 rather than /viewthread.php?id=123 or similar. Apache makes this extremely easy, by automatically adding a '.php' extension to your files if they don't exist. There is even a section on the MirgratingFromApache page that mentions this feature and a few very bad workarounds for it.
I wasn't liking the idea of using a 404 handler to redirect requests, or adding each file to a mod_rewrite rule specifically, so I decided to write a little module to do this ;)
mod_autoext is given a configured list of suffixes (such as '.php'), and then will attempt to append these onto the first segment of the path that doesn't exist, until it finds a match. So, if you have a file called 'existingdir/phpinfo.php', you can do a request like /existingdir/phpinfo/1/2/3 and that will become /existingdir/phpinfo.php/1/2/3 (works fully with pathinfo).
I thought i'd submit it here in hopes of getting it included, since it seems that 3rd party modules are pretty tough for users to put in. It's MIT licensed, so you can do pretty much whatever you like to it.
I tested this on 1.4.15, but not on 1.5.x yet.
Files
Updated by mike503 about 17 years ago
check this page out. it will do what you want... assuming the last part of the url is the script itself.
http://trac.lighttpd.net/trac/wiki/Docs%3AModMagnet#extension-rewrites
i use it for .php on one of my sites, works great.
imho it would be quite expensive to look up each part of the URI for what is a virtual/non-existent file/directory and consider that a URI parameter... i actually wrote something in PHP to do that for me, but figured it's overkill.
for something like that i would just setup rewrite for /existing/phpinfo so the webserver/modules aren't doing extra work to determine what really exists or not.
Updated by gstrauss over 8 years ago
- Description updated (diff)
- Category changed from core to 3rd party
- Assignee deleted (
jan) - Target version changed from 1.5.0 to 1.4.x
Updated by gstrauss over 7 years ago
- Category changed from 3rd party to mod_magnet
- Status changed from New to Fixed
- Target version changed from 1.4.x to 1.4.46
Thanks for the contribution. However, this can already be achieved with some custom lua script and mod_magnet, e.g. modify 'exts' list in
local attr = lighty.stat(lighty.env["physical.path"]) if (not attr) then local ext local exts = { ".php", ".pl", ".foo" } local basepath = lighty.env["physical.path"] for _, ext in ipairs(exts) do local path = basepath .. ext attr = lighty.stat(path) if (attr and attr["is_file"]) then lighty.env["physical.path"] = path lighty.env["physical.rel-path"] = lighty.env["physical.rel-path"] .. ext return 0 end end end return 0
See Docs_ModMagnet for more information about using mod_magnet.
See #2678 for a more advanced example of content-negotiation.lua
Updated by gstrauss over 7 years ago
- Related to Feature #2678: New mod_precompress feature added
Also available in: Atom