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:29]
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 16: Line 16:
 Changing the ruleset order may resolve the issue. Changing the ruleset order may resolve the issue.
  
-Another tip is to use only one ''​[L]''​ in your ruleset instead of multiple ''​[L]''​s.+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. 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.
Line 22: Line 22:
 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.  ​ 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: Changing ​the order of rules ==== +==== Example 1: Change ​the Order of Rules ==== 
-For example:+Let's say you have this for Apache:
  
   RewriteEngine On   RewriteEngine On
Line 41: Line 41:
   RewriteRule ^([^\.]+)$ $1.php [NC,​L] ​   ​   RewriteRule ^([^\.]+)$ $1.php [NC,​L] ​   ​
  
-==== Example 2: use ''<​IfModule litespeed>​ ... </​IfModule>​'' ​for different rules====  +==== Example 2: Use Only One [L] Instead of Multiple ==== 
-For example:+ 
 +Let's say you have this ruleset: 
 + 
 +  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 3: Use "<​IfModule litespeed>​ ... </​IfModule>​" ​for Different Rules====  
 +Change this:
  
   RewriteCond %{REQUEST_URI} !\..*   RewriteCond %{REQUEST_URI} !\..*
Line 67: 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 112: Line 139:
   </​IfModule>​   </​IfModule>​
  
-==== Example ​3use ''​<​IfModule litespeed>​ ... </​IfModule>​'' ​for different blocks====    +==== 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 124: 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:29
  • by Jackson Zhang