Skip to main content

.htaccess Support

Learning Focus

By the end of this lesson you will understand which .htaccess directives OpenLiteSpeed supports, when to use .htaccess versus native configuration, and common pitfalls.

What OpenLiteSpeed Supports

OpenLiteSpeed supports many common .htaccess directives, especially those used by popular PHP applications like WordPress, Laravel, and Drupal. This includes:

  • Rewrite rules (RewriteEngine, RewriteRule, RewriteCond)
  • Redirects (Redirect, RedirectMatch)
  • Access control (Deny, Allow, Require)
  • Headers (Header set, Header unset)
  • Error documents (ErrorDocument)
  • Index files (DirectoryIndex)

What May Not Work

Some Apache-specific directives have no equivalent or behave differently:

DirectiveSupport LevelNotes
RewriteRule✅ FullCore rewrite support
Redirect✅ FullStandard redirects
Header set✅ GoodMost header operations
php_value / php_admin_value⚠️ PartialMay not affect lsphp the same way
mod_deflate directives⚠️ LimitedUse OLS compression settings instead
mod_security inline rules❌ NoConfigure ModSecurity at server level

.htaccess vs Native Configuration

Feature.htaccessNative OLS Config
Edit without reloadYes — changes take effect on next requestNo — requires graceful reload
PerformanceSlightly slower (read on every request)Faster (loaded once at start)
PortabilityWorks across Apache and OLSOLS-specific
Audit clarityScattered across directoriesCentralized in config files
Best forApp-managed rules (CMS, frameworks)Server-managed rules
info

Compatibility does not mean you should put everything in .htaccess. Centralized native configuration is often easier to audit and reason about.

Common .htaccess Examples That Work on OLS

# Typical WordPress .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Force HTTPS Redirect

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Deny Access to Sensitive Files

<FilesMatch "\.(env|ini|log|sh)$">
Require all denied
</FilesMatch>

Troubleshooting .htaccess Issues

# Check if .htaccess is being read
# Enable rewrite logging temporarily in WebAdmin:
# Virtual Host → Rewrite → Log Level → set to a higher value

# Check the error log for rewrite processing
grep -i "rewrite" /usr/local/lsws/logs/error.log | tail -20

Key Takeaways

  • Use .htaccess for portability when applications manage their own routing rules.
  • Prefer native OLS configuration for server-managed rules — it is faster and easier to audit.
  • Test .htaccess changes carefully — some Apache-only directives may silently fail.

What's Next