AutoLoad .htaccess with OpenLiteSpeed

How Can We Help?
< Back
You are here:
Print

As of v1.4.38, OpenLiteSpeed supports the ability to load .htaccess from directories and subdirectories automatically. The old ways of adding rewrite rules manually via the WebAdmin Console or vHost config will continue to work, but if you’re looking to manage your rewrite rules from .htaccess directly, we now have a solution for it, and it is the recommended way for rewrite rules going forward.

You can enable Auto Load from .htaccess from the server level, virtual host level or context level.

Server Level

In the OLS WebAdmin Console, navigate to Server Configuration > General > Rewrite Control and set Auto Load from .htaccess to Yes.

Virtual Host Level

In the OLS WebAdmin Console, navigate to Virtual Hosts > Your VH Name> Rewrite and set Auto Load from .htaccess to Yes. Please also make sure to set Enable Rewrite to Yes.

Alternatively, you can make the changes to your virtual host configuration file directly through vi:


rewrite  {
  enable                  1
  autoLoadHtaccess        1
}

Make sure you restart OLS after changing the file, so that it can be picked up from the virtual host’s root directory.

Context/Directory Level

NOTE: As of v1.5.4, AutoLoad .htaccess can read .htaccess in subdirectories without defining the settings below, assuming it has been enabled at the virtual host level, and the directory is being accessed via HTTP.

To explicitly instruct OpenLiteSpeed to look for .htaccess in a particular directory, you can add a context to your virtual host configuration, like so:


context /dir/ {
allowBrowse             1
}

This will allow OpenLiteSpeed to browse the directory defined in the context and pick up .htaccess from there. You’ll need to add a new context for each subdirectory.

Unsupported Directives

Pleas only add rewrite rules supported by OLS to .htaccess. Unsupported directives will be ignored.

OpenLiteSpeed currently only supports mod_rewrite rules from Apache, so before making it read the .htaccess files, please convert
them to Apache’s mod_rewrite format. You can find some examples here. Remember to restart OLS, after making changes to your rewrite files, so that it can read the new ones.