Help:Rewrite Rule Differences

From OpenLiteSpeed
Jump to: navigation, search

For rewrite rules, OpenLiteSpeed uses the same syntax as Apache's mod_rewrite. Apache rewrite rules can be copied and pasted into OpenLiteSpeed's Rewrite Rules field (WebAdmin > Configuration > Virtual Hosts > your virtual host > Rewrite > Rewrite Rules).

It should be noted, though, that Apache mod_rewrite syntax is slightly different when a rewrite rule is in an .htaccess file as opposed to virtual host configuration (in an httpd.conf file). OpenLiteSpeed rewrite rules should be written in this vhost config syntax. If you are copying a set of rewrite rules from an Apache .htaccess file to OpenLiteSpeed, use the following guidelines to edit the rules so they conform to vhost config syntax.

Conversion Guidelines

Add a forward slash at the beginning of the rule pattern

In a virtual host configuration, the rewrite rule pattern will initially be matched against the part of the URL after the hostname and port and before the query string (e.g. "/app1/index.html"). This part of the URL does not end in a forward slash, so the pattern needs to start with a forward slash. Rewrite rules in an .htaccess file are matched against the file system path, which does end in a forward slash. Thus .htaccess rewrites do not begin with a forward slash, but OpenLiteSpeed rewrites should begin their pattern with a forward slash. See the following example:

In an .htaccess file:

RewriteRule ^([a-zA-Z0-9_-]+)$ http://m.domain.com/$1/ [R=301,L]

In a virtual host configuration (and in OpenLiteSpeed):

RewriteRule ^/([a-zA-Z0-9_-]+)$ http://m.domain.com/$1/ [R=301,L]

RewriteBase is not supported in virtual host configurations

The RewriteBase directive can only be used in .htaccess rewrite rules and thus is not supported in OpenLiteSpeed virtual host configurations. This may result in some very simple substitutions, as in the following example:

In an .htaccess file:

RewriteBase /joomla
RewriteRule .* index.php [F]

In a virtual host configuration (and in OpenLiteSpeed):

RewriteRule /.*  /joomla/index.php [F]

RewriteBase can also be used to direct traffic outside of the document root. To replace this functionality, use an OpenLiteSpeed Context. You can stipulate the URL prefix in the Context's URI and Location settings.)