Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:troubleshooting:rewrite_difference_on_l_flag_between_lsws_and_apache [2019/01/03 20:25]
Jackson Zhang
litespeed_wiki:troubleshooting:rewrite_difference_on_l_flag_between_lsws_and_apache [2019/03/19 15:32] (current)
Lisa Clarke Fixed live example.com links
Line 13: Line 13:
 You may need to tweak your Apache rule set to work with LiteSpeed. You may need to tweak your Apache rule set to work with LiteSpeed.
  
-==== Example 1: Changing the order of rules ==== +==== Tips ==== 
-For example:+Changing the ruleset ​order may resolve the issue. 
 + 
 +Try using only one ''​[L]''​ in your ruleset instead ​of multiple ''​[L]''​s. 
 + 
 +Sometimes the situation may be more complicated. The user may have some rules inherited from an older Apache version, such as Apache 2.2, with a lot of ''​[L]''​s. 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 the ruleset work for LiteSpeed, but that may break it for Apache. In such cases, we would recommend leaving the Apache ruleset untouched, and enclose it with ''<​IfModule !litespeed>​ ... </​IfModule>''​. Then create a new ruleset for LSWS enclosed with ''<​IfModule litespeed>​ ... </​IfModule>''​ as a workable alternative. 
 + 
 +Writing rewrite rules may require a deep understanding of how the rewrite engine works and a talent for coding. The end user's rule may be complicated. They may have inherited a lengthy ruleset from a legacy Apache version, or maybe they are not following best practices, or perhaps they even involve some mistake. The final goal is to tweak the existing rules set to work with both LiteSpeed and Apache as quickly as possible, and not to worry about converting the ruleset into a piece of art.   
 + 
 +==== Example 1: Change the Order of Rules ==== 
 +Let's say you have this for Apache:
  
   RewriteEngine On   RewriteEngine On
Line 32: Line 41:
   RewriteRule ^([^\.]+)$ $1.php [NC,​L] ​   ​   RewriteRule ^([^\.]+)$ $1.php [NC,​L] ​   ​
  
-==== Tipsuse only one [L] or use ''<​IfModule litespeed>​ ... </​IfModule>'' ​==== +==== Example 2Use Only One [L] Instead of Multiple ​====
-Another tip is to use only one ''​[L]''​ in your ruleset instead of multiple ''​[L]''​s.+
  
-Sometimes the situation may be more complicated. The user may have some rules inherited from an older Apache version, such as Apache 2.2, with a lot of ''​[L]'​'s. 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 the ruleset ​work for LiteSpeed, but that may break it for Apache. In such cases, we would recommend leaving the Apache ruleset untouched, and enclose it with ''<​IfModule !litespeed>​ ... </​IfModule>''​. Then create a new ruleset for LSWS enclosed with ''<​IfModule litespeed>​ ... </​IfModule>''​ as a workable alternative.+Let'​s ​say you have this ruleset:
  
-Writing rewrite rules may require a deep understanding of how the rewrite ​engine works and a talent for codingThe end user'rule may be complicatedThey may have inherited a lengthy ruleset from a legacy Apache version, or maybe they are not following best practices, or perhaps they even involve some mistake. The final goal is to tweak the existing rules set to work with both LiteSpeed and Apache as quickly as possible, ​and not to worry about converting ​the ruleset into a piece of art.  ​+  RewriteEngine On 
 +  RewriteBase / 
 +  RewriteRule ^es/(.*)$ /$1 [L] 
 +  RewriteRule ^reservar\.html(.*)$ reservar.php [L] 
 +   
 +Under Apache: 
 +  - A visitor hits the URL ''<​nowiki>​http://​example.com/​es/​reservar.html</​nowiki>''​ . 
 +  - The web server recognizes the pattern ''​^es/​(.*)$''​ from the first rewrite ​rule and the request is internally redirected to ''/​reservar.html''. 
 +  - ''/​reservar.html''​ also matches the rule ''​^reservar\.html(.*)$''​ and is redirected to ''​reservar.php''​. 
 +  - The contents of this latest file (''​reservar.php''​) ​is sent to the visitor. 
 + 
 +Under LiteSpeed ​Web Server: 
 +  - A visitor hits the URL ''<​nowiki>​http://​example.com/​es/​reservar.html</​nowiki>''​ . 
 +  - The web server recognizes the pattern ''​^es/​(.*)$''​ from the first rewrite rule and the request is internally redirected to ''/​reservar.html''​. 
 +  - Processing stops at the first [L] (''​RewriteRule ^es/(.*)$ /$1 [L]''​) ​and never reaches the forth line at all. 
 + 
 +If you want LSWS to process these rules with the same results as Apache, you can update them to use only one [L]: 
 + 
 +  RewriteEngine On 
 +  RewriteBase / 
 +  RewriteRule ^es/(.*)$ /es/$1 [NC] 
 +  RewriteRule ^/​es/​reservar.html(.*)$ reservar.php [L]
  
-==== Example ​2use ''​<​IfModule litespeed>​ ... </​IfModule>​'' ​====  +==== Example ​3Use "<​IfModule litespeed>​ ... </​IfModule>​" for Different Rules====  
-For example:+Change this:
  
   RewriteCond %{REQUEST_URI} !\..*   RewriteCond %{REQUEST_URI} !\..*
Line 65: Line 94:
   RewriteRule (.*) http://​example.com/​$1 [R=301,L]   RewriteRule (.*) http://​example.com/​$1 [R=301,L]
  
-You can change it to:+To this:
  
   RewriteCond %{REQUEST_URI} !\..*   RewriteCond %{REQUEST_URI} !\..*
Line 110: Line 139:
   </​IfModule>​   </​IfModule>​
  
-==== Example ​3use ''​<​IfModule litespeed>​ ... </​IfModule>​'' ​====    +==== Example ​4Use "<​IfModule litespeed>​ ... </​IfModule>​" for Different Blocks====    
-Another example is:+Change this:
   RewriteEngine On   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} -f   RewriteCond %{REQUEST_FILENAME} -f
Line 122: Line 151:
   RewriteRule ^(specials|about_us|links|order_complete|view_cart|checkout).html$ $1.page [L,​QSA]   RewriteRule ^(specials|about_us|links|order_complete|view_cart|checkout).html$ $1.page [L,​QSA]
   ​   ​
-You can make changes like the following:+To this:
   <​IfModule !litespeed>​   <​IfModule !litespeed>​
   RewriteEngine On   RewriteEngine On
  • Admin
  • Last modified: 2019/01/03 20:25
  • by Jackson Zhang