Skip to content
web-casaPublic

About

Make OLS Understand .htaccess and More

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

207 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiteHTTPD -- Apache .htaccess Compatibility for OpenLiteSpeed

Apache .htaccess compatibility module for OpenLiteSpeed, plus the litehttpd-confconv Apache-to-OLS config converter.

Editions

LiteHTTPD-Thin LiteHTTPD-Full
What litehttpd_htaccess.so module only Module + Patched OLS (3 patches)
Install on Stock (unmodified) OLS Custom-built OLS (v1.9.5)
Install time 1 minute 10-15 minutes
Directives 120 (security, headers, caching, conditionals, redirects, native PCRE2 RewriteRule, ESI, 5D BotChallenge + Rust ALTCHA v1, RateLimit, Options -Indexes, Require expr/<RequireNone>/AuthGroupFile, AllowOverrideList) 120 (adds OLS native RewriteEngine, per-request php_value/php_flag, readApacheConf, static zstd 1.5.7, libmodsecurity 3.0.17)
Best for Quick .htaccess support, Docker, evaluation Full Apache migration, WordPress with advanced plugins

LiteHTTPD-Thin works on any stock OLS -- just copy the .so and restart. All 120 security, header, caching, ESI, 5D BotChallenge + ALTCHA v1, RateLimit, Options -Indexes, Require expr/<RequireNone>/AuthGroupFile, AllowOverrideList, and built-in PCRE2 RewriteRule directives work immediately (php_value falls back to LSAPI env variables where supported).

LiteHTTPD-Full compiles OLS v1.9.5 with 3 patches (0001–0003), static libzstd 1.5.7 (-DWITH_ZSTD=ON, zstdAutoUpdateStatic 1), libmodsecurity 3.0.17, pure-std Rust litehttpd-core (statically linked ABI v3: ALTCHA v1, ESI + RFC 9112 chunked dynamic HTTP, ap_expr, unified crypto & Basic Auth/$apr1$/{SHA}, BotChallenge parsers/renderers), lock-free Master-mmap 0640 SHM security metrics (with feature_flags + Cacheline 6), litehttpd-explain (standalone offline .htaccess policy simulator & CI assertion tool), litehttpd-firewalld (privilege-tiered ban/unban/flush + status + metrics CLI + opt-in loopback Prometheus/JSON exporter), litehttpd-audit (real ap_expr validation + SARIF 2.1.0 + explain passthrough), and a versioned ABI handshake (litehttpd_get_abi_info).

Features

  • 120 .htaccess directives (Verified against Live Apache 2.4) -- Header (set/always/append/merge/add/unset/edit/edit*), Redirect (Redirect, RedirectPermanent, RedirectTemp, RedirectMatch with query-string preservation), RewriteRule/RewriteCond ([QSD], [QSA], [E=verifycaptcha]), SetEnv, Expires, php_value/php_flag, Options (-Indexes, -FollowSymLinks), Require expr/not expr, <RequireNone>/<RequireAll>/<RequireAny>, AuthGroupFile + Require group, hardened AuthType Basic ($apr1$/{SHA}/crypt + bcrypt cost cap, HMAC-keyed positive cache & confined auth file loading via HTACCESS_VHROOT / LITEHTTPD_AUTH_ALLOWED_DIRS), DirectoryIndex, FilesMatch, ESI, 5D BotChallenge + ALTCHA v1, RateLimit (action=challenge|ban), LSCache, ModSecurity bridge, and more — backed by our blocking real Apache 2.4 differential suite (COMPATIBILITY_SCOREBOARD.md)
  • Offline Policy Simulator & CI Gate (litehttpd-explain) -- Standalone C11 CLI sharing the exact litehttpd_core_objs object library with litehttpd_htaccess.so (zero OLS daemon, zero SHM/network): 10-stage execution trace (dirwalk → response), --format text|json, --allow-override/--allow-override-list, --auth-env/--auth-file credential redaction, default uid-0 refusal, CI assertions (--expect-status/--expect-header/--expect-location/--expect-uri), and litehttpd-audit explain passthrough
  • Pure-std Rust Security Core (litehttpd-core ABI v3) -- Statically linked into litehttpd_htaccess.so (zero external crates, MSRV 1.75.0, catch_unwind FFI isolation) powering unified SHA-256/HMAC/MD5/SHA-1 crypto, Basic Auth/$apr1$/{SHA}, BotChallenge parsers & HTML/JS renderers, ALTCHA v1 PoW/HMAC, the quote-aware ESI streaming state machine, bounded incremental HTTP/1.1 + RFC 9112 chunked dynamic ESI parsing, and the single-pass ap_expr lexer/AST parser
  • Zero-Intrusion Security Observability -- 4 KB cacheline-aligned atomic SHM page (/run/litehttpd/metrics.shm, Master-mmap 0640 with immediate close(fd) before fork(), rolling-upgrade feature_flags + Cacheline 6), litehttpd-firewalld metrics [--prometheus|--json] CLI (including litehttpd_firewalld_active_cidr_bans), and opt-in non-blocking loopback HTTP /metrics exporter (zero IP lists exposed)
  • Native 5D Bot Defense & Pure-std Rust ALTCHA v1 -- BotChallengeMode on-demand, RateLimit action=challenge|ban, opt-in BotChallengeFailLimit, BotChallengeConnLimit, BruteForceAction challenge|challenge-drop, [E=verifycaptcha], BotChallengePreset, BotChallengeEscalate firewall, BotChallengeDebugHeader, and zero-CDN SHA-256 BotChallengeProvider altcha
  • Rust Ops & Migration CLI -- litehttpd-firewalld (admin-only IPv4/IPv6 CIDR & single-IP ban/unban/flush --source|--all --yes with SO_PEERCRED tiering & non-overlap guards, status [--source <src>] [--json], metrics [--prometheus|--json]) and litehttpd-audit [--format text|json|sarif] [--strict] (read-only 120-directive .htaccess structural stack, real ap_expr, config-bounds & security-advisory auditor + explain subcommand)
  • If/ElseIf/Else conditional blocks & Require [not] expr with ap_expr engine (&&, ||, !, -f, -d, -ipmatch, regex, functions)
  • RewriteOptions inherit/IgnoreInherit and native/OLS RewriteEngine execution
  • IPv4/IPv6 CIDR access control with IPv4-mapped IPv6 unwrapping (::ffff:), Require ip/Require not ip, Require env, Require group, <RequireNone>, and Satisfy
  • AllowOverride ∪ AllowOverrideList category and per-directive governance filtering (AuthConfig, FileInfo, Indexes, Limit, Options + 64-token directive allowlist with fail-closed container protection)
  • HTACCESS_VHROOT three-level .htaccess merging
  • litehttpd-confconv: Apache httpd.conf to OLS config converter (65+ directives, panel detection, Macro support, SSL extended)
  • readApacheConf: Embedded Apache config parser in OLS binary (like CyberPanel/LSWS)

Quick Start

LiteHTTPD-Full (RPM, EL 8/9/10)

One RPM installs everything: patched OLS + litehttpd module + auto-configuration.

# Add repository and install (recommended)
curl -s https://rpms.litehttpd.com/setup.sh | bash
dnf install openlitespeed-litehttpd

# Or download RPM directly from https://rpms.litehttpd.com/
rpm -ivh openlitespeed-litehttpd-1.9.5-1.litehttpd.el9.x86_64.rpm

# Restart OLS
/usr/local/lsws/bin/lswsctrl restart

The RPM %post automatically:

  • Enables the litehttpd module in httpd_config.conf
  • Enables vhost rewrite (for WordPress permalinks)
  • Adds index.php to indexFiles

PHP is not included — install your preferred PHP separately (lsphp from LiteSpeed repo, or php-litespeed from Remi).

LiteHTTPD-Thin (stock OLS, any platform)

For stock (unpatched) OLS. Download the .so from rpms.litehttpd.com:

# Download module for your platform (el8/el9/el10/ubuntu22)
curl -LO https://rpms.litehttpd.com/el9/x86_64/RPMS/litehttpd_htaccess-el9-x86_64.so
cp litehttpd_htaccess-el9-x86_64.so /usr/local/lsws/modules/litehttpd_htaccess.so

# Enable module
cat >> /usr/local/lsws/conf/httpd_config.conf <<'EOF'

module litehttpd_htaccess {
    ls_enabled              1
}
EOF

# Enable rewrite in vhost (required for WordPress permalinks)
VHCONF=/usr/local/lsws/conf/vhosts/Example/vhconf.conf
sed -i '/^rewrite {/,/^}/s/enable 0/enable 1/' $VHCONF
sed -i 's/indexFiles index.html/indexFiles index.php, index.html/' $VHCONF

# Restart OLS
/usr/local/lsws/bin/lswsctrl restart

Note: Thin mode supports all 120 directives including Require expr/<RequireNone>/AuthGroupFile, AllowOverrideList, built-in PCRE2 RewriteRule ([QSD], [E=verifycaptcha]), 5D BotChallenge + Rust ALTCHA v1, and module-enforced Options -Indexes. Full mode adds OLS-native RewriteEngine, per-request PHPConfig (php_value/php_flag), set_req_header, and readApacheConf.

Apache Config Conversion

LiteHTTPD provides two ways to convert Apache httpd.conf to OLS format, using the same parser (65+ directives, panel detection, Macro support, SSL extended):

readApacheConf (recommended for production)

Add one line to OLS config -- Apache config is parsed in-process at startup (like CyberPanel/LSWS):

# In /usr/local/lsws/conf/httpd_config.conf:
readApacheConf /etc/httpd/conf/httpd.conf portmap=80:8088,443:8443

OLS starts, parses the Apache config, generates native OLS vhost/listener configs, and loads them automatically. No external tools, no fork/exec.

litehttpd-confconv CLI (for migration, debugging, CI)

Standalone tool for manual conversion, change detection, and hot-reload:

# One-time conversion
litehttpd-confconv --input /etc/httpd/conf/httpd.conf \
                   --output /usr/local/lsws/conf/apacheconf/ \
                   portmap=80:8088,443:8443

# Check if Apache config changed (for CI/scripts)
litehttpd-confconv --check /etc/httpd/conf/httpd.conf --state /var/run/confconv.state
# Exit: 0=changed, 1=unchanged, 2=error

# Watch mode (auto-reconvert on changes)
litehttpd-confconv --watch /etc/httpd/conf/httpd.conf --interval 60 \
                   --output /usr/local/lsws/conf/apacheconf/

Both use the same parser. readApacheConf is for "set and forget" production use; the CLI is for migration previews, debugging, CI pipelines, and llstack integration.

OLS Patches

Three patches extend OpenLiteSpeed 1.9.5 for full functionality (Options -Indexes 403 is enforced directly inside litehttpd_htaccess.so, so the legacy autoindex patch is no longer needed):

Patch Description
0001-lsiapi-phpconfig.patch Per-request PHPConfig (php_value/php_flag to lsphp), set_req_header, and versioned ABI handshake (litehttpd_get_abi_info)
0002-lsiapi-rewrite.patch RewriteRule engine LSIAPI extensions (parse/exec/free with RewriteBase override)
0003-readapacheconf.patch Embedded Apache config parser + readApacheConf directive (heap-allocated config, post-parse portmap=)

Apply to OLS 1.9.5 source before building:

cd openlitespeed-1.9.5/
# Copy confconv parser/writer into OLS source tree (needed by patch 0003)
cp /path/to/apacheconf_parser.{c,h} src/main/
cp /path/to/ols_config_writer.{c,h} src/main/
# Apply patches in order
patch -p1 < 0001-lsiapi-phpconfig.patch
patch -p1 < 0002-lsiapi-rewrite.patch
patch -p1 < 0003-readapacheconf.patch

Without patches, the module still works on stock OLS -- RewriteRule uses the built-in PCRE2 rewrite engine, Options -Indexes is enforced by the module, and php_value/php_flag degrade safely.

Building from Source

Requirements

  • CMake >= 3.14
  • GCC or Clang with C11 support
  • libpcre2-dev / pcre2-devel and pkg-config
  • libcrypt-dev / libxcrypt-devel
  • Rust toolchain (only if building optional firewalld/)

Build

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)

# Output:
#   build/litehttpd_htaccess.so   -- the module
#   build/litehttpd-confconv      -- the config converter

Build without tests

cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF
cmake --build build -j$(nproc)

Testing

The project includes 1,296+ C/C++ tests via CTest, 104+ pure-std Rust unit/mutation-fuzz/UDS integration tests (litehttpd-core, litehttpd-audit, litehttpd-firewalld), and a 6-target Clang libFuzzer suite (-DBUILD_FUZZING=ON) gated in CI (fuzz-smoke):

cmake -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j$(nproc)

# Run all C/C++ tests (unit, property, compat, confconv, ESI, SHM, BotChallenge, concurrency, ABI)
ctest --test-dir build --output-on-failure -j$(nproc)

# Run Rust firewalld checks & tests
cargo fmt --manifest-path firewalld/Cargo.toml --check
cargo clippy --manifest-path firewalld/Cargo.toml --all-targets -- -D warnings
cargo test --manifest-path firewalld/Cargo.toml

Consistency & patch checks

Verifies all 98 directive types are covered across parser, printer, executor, dirwalker, free, and generator:

bash tests/check_consistency.sh
bash tests/check_patches.sh

Sanitizers (ASan + LSan + UBSan)

cmake -B build-san -DCMAKE_BUILD_TYPE=Debug \
  -DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
  -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined"
cmake --build build-san -j$(nproc)
ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
  ctest --test-dir build-san --output-on-failure -j$(nproc)

Supported Directives

Full list of 98 supported directives

Headers: Header set/unset/append/merge/add/edit/edit*, Header always set/unset/append/merge/add/edit/edit*, RequestHeader set/unset

PHP: php_value, php_flag, php_admin_value, php_admin_flag

Access Control: Order, Allow/Deny from, Require all granted/denied, Require ip, Require not ip, Require env, Require valid-user, RequireAny, RequireAll, Satisfy

Authentication: AuthType, AuthName, AuthUserFile

Redirects: Redirect, RedirectMatch, ErrorDocument

Rewrite: RewriteEngine, RewriteBase, RewriteCond, RewriteRule, RewriteOptions (RewriteMap is parsed/recognized only and intentionally disabled in .htaccess for security; configure RewriteMap in native OLS vhost config)

Conditionals: If, ElseIf, Else, IfModule

Content: AddType, AddEncoding, AddCharset, AddDefaultCharset, DefaultType, ForceType, DirectoryIndex, RemoveType, AddHandler¹, SetHandler¹, RemoveHandler¹, Action¹

Caching: ExpiresActive, ExpiresByType, ExpiresDefault

Environment: SetEnv, SetEnvIf, SetEnvIfNoCase, BrowserMatch

Containers: Files, FilesMatch, Limit, LimitExcept

Options: Options

Brute Force: LSBruteForceProtection, LSBruteForceAllowedAttempts, LSBruteForceWindow, LSBruteForceAction, LSBruteForceThrottleDuration, LSBruteForceXForwardedFor, LSBruteForceWhitelist, LSBruteForceProtectPath

¹ Parsed but no-op: OLS uses scriptHandler in vhost config instead of .htaccess handler directives. These directives are recognized and logged but do not change request handling.

Performance

Benchmark Results (v2.0.0, Linode 4C/8G EL9, WordPress, PHP 8.3, MariaDB 10.11)

Functional Compatibility

Test Apache OLS-Thin OLS-Full Stock OLS
WordPress Home ✅ 200 ✅ 200 ✅ 200 ✅ 200
Pretty Permalink ✅ 200 ✅ 200 ✅ 200 ✅ 200
Security Headers (nosniff, X-Frame) ✅ ✅ ✅ ❌
wp-config.php blocked ✅ 403 ✅ 403 ✅ 403 ❌ 200
xmlrpc.php blocked ✅ 403 ✅ 403 ✅ 403 ❌ 405
.htaccess blocked ✅ 403 ✅ 403 ✅ 403 ✅ 403
Pass rate 10/10 10/10 10/10 6/10

Performance

Metric Apache Stock OLS OLS-Full (RPM)
Static RPS 23,909 63,140 58,891
PHP RPS (wp-login) 274 258 292
Permalink RPS 69 1.1 1.1

Resource Usage (after load)

Metric Apache Stock OLS OLS-Full (RPM)
Total Memory 818 MB 654 MB 689 MB
Server RSS 618 MB 320 MB 449 MB
Process Count 18 14 17
  • OLS-Full (RPM): One RPM install — patched OLS + bundled module + auto-configured
  • Stock OLS: Official OLS without .htaccess module

Key findings:

  • OLS-Full achieves 100% Apache .htaccess compatibility (10/10 vs Stock OLS 6/10)
  • Static performance 2.5x faster than Apache with 20% less memory
  • PHP performance slightly better than Apache (292 vs 274 rps)
  • Stock OLS exposes wp-config.php (200) — security risk without .htaccess
  • Permalink rewrite is slow on all OLS engines (OLS architecture limitation)

WordPress Plugin Compatibility (10 plugins, .htaccess dependent)

Tested with: Wordfence, All In One WP Security, W3 Total Cache, WP Super Cache, Yoast SEO, Redirection, WPS Hide Login, Disable XML-RPC, iThemes Security, HTTP Headers

Test Apache OLS-Full (RPM)
Home (10 plugins active) ✅ 200 ✅ 200
Pretty Permalink ✅ 200 ✅ 200
Yoast Sitemap ✅ 200 ✅ 200
xmlrpc blocked ✅ 403 ✅ 403
wp-config protected ✅ 403 ✅ 403
Security Headers ✅ nosniff + xframe ✅ nosniff + xframe
Cache Headers on JS ✅ 2 headers ✅ 2 headers
REST API ✅ 200 ✅ 200
RSS Feed ✅ 200 ✅ 200
Result 9/9 match 9/9 match

OLS-Full produces identical results to Apache on all .htaccess-dependent plugin tests.

Previous benchmark (5-engine, 19 WP plugins): tests/e2e/vps-5engine/benchmark-results.md

PHP Performance Tuning

LiteHTTPD uses lsphp (LSAPI protocol) for PHP processing. The default OLS configuration starts a single lsphp process and forks on demand, which causes slow cold starts under load. To match Apache PHP-FPM performance, configure lsphp worker pool size:

# In httpd_config.conf extprocessor section:
extProcessor lsphp {
    ...
    env                     PHP_LSAPI_CHILDREN=10
    env                     PHP_LSAPI_MAX_IDLE=300
    ...
}
Config PHP RPS (wp-login.php, c=5) Behavior
Default (CHILDREN=1) ~5 rps Fork on demand, cold start ~1s per request
CHILDREN=10 ~15-20 rps Pre-forked pool, no cold start
Apache PHP-FPM (pm=dynamic) ~16 rps Pre-forked pool (reference)

Note: Stock OLS and LSWS may show very high PHP RPS (20K-35K) in benchmarks due to built-in page caching (LSCache). This is the cache module returning stored responses, not actual PHP execution. LiteHTTPD does not include a page cache module — use LiteSpeed Cache WordPress plugin with OLS native cache module for equivalent behavior.

Troubleshooting

WordPress permalinks return 404

OLS defaults to rewrite { enable 0 } in vhost config. The .htaccess RewriteRule is parsed by litehttpd but OLS's rewrite engine won't execute it unless vhost-level rewrite is enabled.

Fix: Edit your vhost config (e.g., /usr/local/lsws/conf/vhosts/Example/vhconf.conf):

rewrite {
  enable                  1    # <-- change from 0 to 1
  logLevel                0
}

Then restart OLS: /usr/local/lsws/bin/lswsctrl restart

PHP files return 403 "access denied"

OLS needs a scriptHandler mapping PHP to lsphp. Check that your httpd_config.conf has:

scriptHandler {
    add lsapi:lsphp php    # name must match extProcessor name
}

And the extProcessor lsphp path points to the correct lsphp binary (e.g., $SERVER_ROOT/lsphp83/bin/lsphp).

Directory index returns 404 (e.g., /wordpress/)

OLS default indexFiles only includes index.html. Add index.php:

index {
    indexFiles index.php, index.html
}

Project

LiteHTTPD is a sub-project of Web.Casa, an AI-native open source server control panel.

Related project: LLStack -- a server management platform built on LiteHTTPD.

License

This project is licensed under the GNU General Public License v3.0 -- see LICENSE for details.

OpenLiteSpeed is developed by LiteSpeed Technologies and is also GPLv3 licensed.

About

Make OLS Understand .htaccess and More

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages