This is an old revision of the document!


Minor difference on [L] flag in rewrite rules between LSWS and Apache

The [L] flag (last flag) causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. LSWS does exactly like that and exit from the rewrite completely to avoid rules looping. However, Apache may run the ruleset again for the rewritten request(next iteration or integrations). In another word, for Apache, the [L] flag means “do not process any rules below in this iteration”(but not including future interactions). Therefore ruleset after [L] may still be processed on Apache, but not on LSWS.

On Apache 2.4 and above, an alternative flag, [END], has been introduced to terminate not only the current round of rewrite processing but prevent any subsequent rewrite processing from occurring in .htaccess. [L] flag to LSWS is equivalent to [END] to Apache 2.4.

How to make the Apache rules work with LiteSpeed? You may need to tweak your rule set to meet your requirement.

For exmaple:

RewriteEngine On
RewriteRule ^([^\.]+)$ $1.php [NC,L]                                                
RewriteRule plato-(.*)- plato_hizmet.php?plato=$1              
RewriteRule isik-(.*)- isik_hizmet.php?isik=$1               
RewriteRule hizmetler-(.*)- hizmetler.php?Git=$1             
RewriteRule ekipmanlar-(.*)- ekipmanlar.php?urun=$1

When the second line RewriteRule ^([^\.]+)$ $1.php [NC,L] matched, LSWS will exit the rewrite and won't process any rules below while Apache may continue to process the rest rules at next iteration. Change the rule order to the last line should resolve the problem.

RewriteEngine On
RewriteRule plato-(.*)- plato_hizmet.php?plato=$1              
RewriteRule isik-(.*)- isik_hizmet.php?isik=$1               
RewriteRule hizmetler-(.*)- hizmetler.php?Git=$1             
RewriteRule ekipmanlar-(.*)- ekipmanlar.php?urun=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]    

Another tip is to use only one [L] in your ruleset instead of Multi [L]s.

Sometimes the situation may be more complicated since the user may have some rules inherited from older apache version such as Apache 2.2 with a lot of [L]s and it may not be easy to make it work for both Apache and LiteSpeed at the same time by simply changing the rule order or removing some [L]s. You may try to make ruleset work for LiteSpeed, but it may break with Apache. In such cases, we would recommend leaving apache ruleset untouched enclosed with <IfModule !litespeed> … </IfModule> and create a new ruleset to fit with LSWS enclosed with <IfModule litespeed> … </IfModule> as a workable alternative. Writing rewrite rules may require deep understanding how rewrite engine works and also pieces of arts about coding skills. End user's rule may be complicated, such as inheriting lengthy ruleset from a legacy Apache version or not following best practice or even involving some mistake/misunderstood, the final goal is to tweak existing rules set to work with LiteSpeed and Apache as quick as you can, instead of converting the ruleset to a piece of art.

For example:

RewriteCond %{REQUEST_URI} !\..*
RewriteRule (.*)/+(.*) $1_$2 [L]
RewriteCond %{REQUEST_URI} !\..*
RewriteRule (.*)/+(.*)/+(.*) $1_$2_$3 [L]
RewriteCond %{REQUEST_URI} !\..*
RewriteRule general/(.*) general_$1 [L]
RewriteCond %{REQUEST_URI} !\..*
RewriteRule sitebuilder/(.*) sitebuilder_$1 [L,PT]
RewriteCond %{REQUEST_URI} !\..*
RewriteRule html-editor/(.*) html-editor_$1 [L]
RewriteCond %{REQUEST_URI} !\..*
RewriteRule presenter/(.*) presenter_$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..*
RewriteCond %{REQUEST_URI} !\/$
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.php
RewriteCond %{REQUEST_URI} \..*
RewriteRule (.*) http://example.com/$1 [R=301,L]

You can change it to:

RewriteCond %{REQUEST_URI} !\..*
<IfModule LiteSpeed>
RewriteRule (.*)/+(.*) $1_$2
</IfModule>
<IfModule !LiteSpeed>
RewriteRule (.*)/+(.*) $1_$2 [L]
</IfModule>
RewriteCond %{REQUEST_URI} !\..*
<IfModule LiteSpeed>
RewriteRule (.*)/+(.*)/+(.*) $1_$2_$3
</IfModule>
<IfModule !LiteSpeed>
RewriteRule (.*)/+(.*)/+(.*) $1_$2_$3 [L]
</IfModule>
RewriteCond %{REQUEST_URI} !\..*
<IfModule LiteSpeed>
RewriteRule general/(.*) general_$1
</IfModule>
<IfModule !LiteSpeed>
RewriteRule general/(.*) general_$1 [L]
</IfModule>
RewriteCond %{REQUEST_URI} !\..*
<IfModule LiteSpeed>
RewriteRule sitebuilder/(.*) sitebuilder_$1
</IfModule>
<IfModule !LiteSpeed>
RewriteRule sitebuilder/(.*) sitebuilder_$1 [L,PT]
</IfModule>
RewriteCond %{REQUEST_URI} !\..*
<IfModule LiteSpeed>
RewriteRule html-editor/(.*) html-editor_$1
</IfModule>
<IfModule !LiteSpeed>
RewriteRule html-editor/(.*) html-editor_$1 [L]
</IfModule>
RewriteCond %{REQUEST_URI} !\..*
<IfModule LiteSpeed>
RewriteRule presenter/(.*) presenter_$1
</IfModule>
<IfModule !LiteSpeed>
RewriteRule presenter/(.*) presenter_$1 [L]
</IfModule>

Another example is:

RewriteEngine On
RewriteCond	%{REQUEST_FILENAME}	-f
RewriteRule	^(.*)\.page$	page.php?__page=$1	[L,QSA]
RewriteCond	%{REQUEST_FILENAME}	-f
RewriteRule	^pics/(.*)	pic.php?name=$1		[L,QSA]
RewriteRule	^index\.(html|shtml|htm)$	index.php		[L,QSA]
RewriteRule	^products-(.*)\.html$	products.page?c=$1	[L,QSA]
RewriteRule	^product-(.*)\.html$	product.page?id=$1	[L,QSA]
RewriteRule	^(specials|about_us|links|order_complete|view_cart|checkout).html$	$1.page		[L,QSA]

You can make changes like the following:

<IfModule !litespeed>
RewriteEngine On
RewriteCond	%{REQUEST_FILENAME}	-f
RewriteRule	^(.*)\.page$	page.php?__page=$1	[L,QSA]
RewriteCond	%{REQUEST_FILENAME}	-f
RewriteRule	^pics/(.*)	pic.php?name=$1		[L,QSA]
RewriteRule	^index\.(html|shtml|htm)$	index.php		[L,QSA]
RewriteRule	^products-(.*)\.html$	products.page?c=$1	[L,QSA]
RewriteRule	^product-(.*)\.html$	product.page?id=$1	[L,QSA]
RewriteRule	^(specials|about_us|links|order_complete|view_cart|checkout).html$	$1.page		[L,QSA]
</IfModule>
<IfModule litespeed>
RewriteRule     ^index\.(html|shtml|htm)$       index.php
RewriteRule     ^products-(.*)\.html$   products.page?c=$1
RewriteRule     ^product-(.*)\.html$    product.page?id=$1
RewriteRule     ^(specials|about_us|links|order_complete|view
RewriteCond     %{REQUEST_FILENAME}     -f
RewriteRule     ^pics/(.*)      pic.php?name=$1         [L,QSA]
RewriteCond     %{REQUEST_FILENAME}     -f
RewriteRule     ^(.*)\.page$    page.php?__page=$1      [L,QSA] 
</IfModule>       
  • Admin
  • Last modified: 2019/01/03 16:31
  • by Jackson Zhang