Features Pricing Docs Blog Log In Get Started Free

OLS Rewrite Rules (htaccess Alternative)

Rewrite Rules on OpenLiteSpeed

Unlike Apache, OpenLiteSpeed does not use .htaccess files by default for performance reasons. Rewrite rules are configured in the virtual host configuration file. However, OLS does support .htaccess if enabled.

Where Rules Are Stored

On BlitzPress, rewrite rules live in the vhost configuration:

/usr/local/lsws/conf/vhosts/YOUR_DOMAIN/vhconf.conf

The rewrite section looks like this:

rewrite {
  enable                  1
  autoLoadHtaccess        1
  rules                   <<<END_rules
  RewriteRule .* - [E=noabort:1]
  # WordPress permalink rewrite
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  END_rules
}

htaccess Support

When autoLoadHtaccess is set to 1, OLS reads .htaccess files from the document root. This means most Apache rewrite rules work on OLS without changes. However, for best performance, put rules in vhconf.conf directly.

Common Rewrite Rules

Force HTTPS:

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

Redirect www to non-www:

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Block access to a directory:

RewriteRule ^wp-includes/ - [F,L]

Custom redirect:

RewriteRule ^old-page/?$ /new-page/ [R=301,L]

Syntax Differences from Apache

  • OLS supports most Apache mod_rewrite directives
  • RewriteBase is not needed in vhconf.conf
  • Some advanced Apache flags may not be supported — test after adding rules
  • After editing vhconf.conf, perform a graceful restart: sudo systemctl restart lsws

Applying Changes

Changes to .htaccess take effect immediately. Changes to vhconf.conf require an OLS restart:

sudo systemctl restart lsws