.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:
| Directive | Support Level | Notes |
|---|---|---|
RewriteRule | ✅ Full | Core rewrite support |
Redirect | ✅ Full | Standard redirects |
Header set | ✅ Good | Most header operations |
php_value / php_admin_value | ⚠️ Partial | May not affect lsphp the same way |
mod_deflate directives | ⚠️ Limited | Use OLS compression settings instead |
mod_security inline rules | ❌ No | Configure ModSecurity at server level |
.htaccess vs Native Configuration
| Feature | .htaccess | Native OLS Config |
|---|---|---|
| Edit without reload | Yes — changes take effect on next request | No — requires graceful reload |
| Performance | Slightly slower (read on every request) | Faster (loaded once at start) |
| Portability | Works across Apache and OLS | OLS-specific |
| Audit clarity | Scattered across directories | Centralized in config files |
| Best for | App-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
WordPress Permalink Rules
# 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
.htaccessfor portability when applications manage their own routing rules. - Prefer native OLS configuration for server-managed rules — it is faster and easier to audit.
- Test
.htaccesschanges carefully — some Apache-only directives may silently fail.
What's Next
- Return to the Server Configuration overview for the full module map.