Actions

Help

Difference between revisions of "Rewrite Rule Differences"

From OpenLiteSpeed Wiki

Line 1: Line 1:
 
For rewrite rules, OpenLiteSpeed uses the same syntax as Apache's [http://httpd.apache.org/docs/current/mod/mod_rewrite.html 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).  
 
For rewrite rules, OpenLiteSpeed uses the same syntax as Apache's [http://httpd.apache.org/docs/current/mod/mod_rewrite.html 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 [http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule Apache mod_rewrite syntax is slightly different when a rewrite rule is in an .htaccess file as opposed to an httpd.conf file]. OpenLiteSpeed rewrite should be written in this httpd.conf 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.
+
It should be noted, though, that [http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule 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 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.
 +
 
 +
=== 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 a forward slash needs to be added to the rules. See the following example:
 +
 
 +
In an .htaccess file:
 +
 
 +
<pre>RewriteRule ^([a-zA-Z0-9_-]+)$ http://m.domain.com/$1/ [R=301,L]</pre>
 +
 
 +
In a virtual host configuration (and in OpenLiteSpeed):
 +
 
 +
<pre>RewriteRule ^/([a-zA-Z0-9_-]+)$ http://m.domain.com/$1/ [R=301,L]</pre>

Revision as of 17:09, 12 December 2014

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 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.

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 a forward slash needs to be added to the rules. 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]