Sample Header Ad - 728x90

Apache: rewrite URI path to (canonical) mixed case version and load actual content via an Alias?

0 votes
0 answers
26 views
We need to do some URI mangling for some web content that (for historical reasons) has been promoted using mixed case URIs. The address is www.domain.invalid/ACRONYM/pROJECT (with various pages contained within that folder). /ACRONYM/pROJECT is actually ultimately served from a UserDir: AliasMatch "(?i)^/ACRONYM/pROJECT(.*)" "/home/someuser/htdocs/pROJECT$1" What I want to do is convert requests for lower (well, any - hence NC (NoCase) flag) case requests to the "canonical" mixed case form (so that this is what is presented to site visitors), and then load the content from the UserDir via the Alias: RewriteRule "^/acronym/project(.*)$" "/ACRONYM/pROJECT$1" [NC] …with the AliasMatch rule (referred to above) following this in my server config (am I right in thinking that both Redirect and also Rewrite are applied before any Alias?). I am also not sure whether I might need a RewriteCond of some sort here? I have **[LogLevel alert rewrite:trace2](https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging)** temporarily enabled on my test server, and it **seems** that mod_rewrite is indeed converting the request to the desired URI case, but Apache then seems to be trying to look in the filesystem under the DocumentRoot, rather than having followed the Alias? (Other, simpler, Alias'es on the server, without this cumbersome two-stage process, do work OK.) Example log output:
rewrite '/acronym/project/somepage' -> '/ACRONYM/pROJECT/somepage'
setting lastsub to rule with output /ACRONYM/pROJECT$1
local path result: /ACRONYM/pROJECT/somepage
prefixed with document_root to /var/www/html/ACRONYM/pROJECT/somepage
go-ahead with /var/www/html/ACRONYM/pROJECT/somepage [OK]
Asked by dave559 (451 rep)
Apr 11, 2025, 04:16 PM