Differences

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

Link to this comparison view

Both sides previous revision Previous revision
litespeed_wiki:cache:litemage:troubleshooting:how-to-fix-rewrite-rule-which-break-litemage-esi [2017/05/11 21:46]
Jackson Zhang
litespeed_wiki:cache:litemage:troubleshooting:how-to-fix-rewrite-rule-which-break-litemage-esi [2017/05/16 13:33] (current)
Lisa Clarke
Line 1: Line 1:
-====== How to fix "an error occurred while processing this directive"​======+~~NOTOC~~ 
 +====== How to Fix "an error occurred while processing this directive" ​Message ​======
  
-After enabling LiteMage, the store shows "an error occurred while processing this directive"​. ​All esi blocks ​got this error message ​and none of the ESI request was sent to the magento ​backend.+===== Problem ===== 
 +After enabling LiteMage, the store displays ​"an error occurred while processing this directive" ​wherever an ESI block should beThis occurs in all ESI blocksand as we see when we turn on LiteMage'​s debug log, none of the ESI requests have been sent to the Magento ​backend ​after the main page request.
  
 {{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​an-error-occurred-while-processing-this-directive.png?​800 |}} {{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​an-error-occurred-while-processing-this-directive.png?​800 |}}
  
-Turn on litemage debug logwe only see the main request coming inbut no any subsequent esi request.+===== Solution ===== 
 +Determine whether the store uses a page optimization plugin. If sothis could be the source of the problemas it changes the html after LiteMage injects <​ESI:​include>​ for hole punching
  
-Try to locate if the store uses some page optimization plugin, ​which could be the source of the problem, as it change the html after LiteMage inject esi:​include ​for hole punching. In the endsuch optimization plugin can not be located.+If no such optimization plugin ​is in useanother common cause is rewritten URLs. If something rewrites ​the URLs for <ESI:include> directivesthat will break LiteMage
  
-A common cause is that something rewrite the URLs for ESI:include directives which breaks litemage. Need to turn of rewrite log and server debug log for it. If https is used for the store, ​make sure you enabled ​the rewrite log on both 80 and 443 virtual ​host.+To investigate,​ we need to turn on the rewrite log and the server debug log. If https is used for the store, ​enable ​the rewrite log on both 80 and 443 virtual ​hosts.
  
 +  - Add the following to the virtual host and restart the web server: ''​RewriteLogLevel 9''​
 +  - Enable LSWS debug log: ''​ps -ef | grep litespeed''​ to check the child process PID, then ''​kill -USR2 <​PID>''​ to enable the debug log.
 +  - Rename the old error log file: ''​mv error_log error_log.bak1''​
 +  - Run a URL test from the browser to trigger the error.
 +  - Rename the new error log file: ''​mv error_log log2check''​
 +  - Turn off the debug log, by running the same command again: ''​kill -USR2 <​PID>''​
 +  - Look at the saved debug log: ''​vi log2check''​
 +  ​
 +We see some rewrite rules have redirected ''/​litemage/​esi'',​ which causes ESI blocks not to work in LiteMage:
  
- +<code
-You will need to add the following to the virtual host and restart web server. +Error log: 
-  RewriteLogLevel 9 +2017-05-11 20:​57:​23.959 [INFO] [108.162.219.111:​32659#​APVH_82.147.14.70:​S-2#​APVH_82.147.14.70:​443_staging.somedomain.] ​
-Then enable LSWS debug log by the following command +
-  ps -ef | grep litespeed +
-to check the child process PID. +
-then +
-  kill -USR2 <PID+
-to enable debug log. +
- +
-You will need to mv the old error log file to other name. +
-  mv error_log error_log.bak1 +
-then run a URL test from browser to trigger the error. +
-then  +
-  mv error_log log2check +
-then turn off the debug log, run the same command again: +
-  kill -USR2 <​PID>​ +
- +
-By investigating the debug log: vi log2check, some rewrite rules have redirect /​litemage/​esi,​ which break LiteMage. +
- +
-  ​Error log: +
-  2017-05-11 20:​57:​23.959 [INFO] [108.162.219.111:​32659#​APVH_82.147.14.70:​S-2#​APVH_82.147.14.70:​443_staging.somedomain.] ​+
 [REWRITE] Cond: Match  [REWRITE] Cond: Match 
-  ​'/​litemage/​esi/​getBlock/​t/​cart/​bi/​cart_sidebar/​h/​D/​extra/​YToxOntzOjk6ImFqYXhibG9jayI7YjoxO30,/​s/​1/​dp/​em0141/​dt/​em0141_shoes'​ with pattern '​(.*)/​$',​ result: -1 +'/​litemage/​esi/​getBlock/​t/​cart/​bi/​cart_sidebar/​h/​D/​extra/​YToxOntzOjk6ImFqYXhibG9jayI7YjoxO30,/​s/​1/​dp/​em0141/​dt/​em0141_shoes'​ with pattern '​(.*)/​$',​ result: -1 
-  2017-05-11 20:​57:​23.959 [INFO] [108.162.219.111:​32659#​APVH_82.147.14.70:​S-2#​APVH_82.147.14.70:​443_staging.somedomain.] [REWRITE] Source URI:  +2017-05-11 20:​57:​23.959 [INFO] [108.162.219.111:​32659#​APVH_82.147.14.70:​S-2#​APVH_82.147.14.70:​443_staging.somedomain.] [REWRITE] Source URI:  
-  '​litemage/​esi/​getBlock/​t/​cart/​bi/​cart_sidebar/​h/​D/​extra/​YToxOntzOjk6ImFqYXhibG9jayI7YjoxO30,/​s/​1/​dp/​em0141/​dt/​em0141_shoes/'​ =>  +'​litemage/​esi/​getBlock/​t/​cart/​bi/​cart_sidebar/​h/​D/​extra/​YToxOntzOjk6ImFqYXhibG9jayI7YjoxO30,/​s/​1/​dp/​em0141/​dt/​em0141_shoes/'​ =>  
-  Result URI: '​http://​staging.somedomain.co.uk/​litemage/​esi/​getBlock/​t/​cart/​bi/​cart_sidebar/​h/​D/​extra/​YToxOntzOjk6ImFqYXhibG9jayI7YjoxO30,/​s/​1/​dp/​em0141/​dt/​em0141_shoes/'​ +Result URI: '​http://​staging.somedomain.co.uk/​litemage/​esi/​getBlock/​t/​cart/​bi/​cart_sidebar/​h/​D/​extra/​YToxOntzOjk6ImFqYXhibG9jayI7YjoxO30,/​s/​1/​dp/​em0141/​dt/​em0141_shoes/'​ 
-  2017-05-11 20:​57:​23.959 [INFO] [108.162.219.111:​32659#​APVH_82.147.14.70:​S-2#​APVH_82.147.14.70:​443_staging.somedomain.] [REWRITE] Last Rule, stop!+2017-05-11 20:​57:​23.959 [INFO] [108.162.219.111:​32659#​APVH_82.147.14.70:​S-2#​APVH_82.147.14.70:​443_staging.somedomain.] [REWRITE] Last Rule, stop! 
 +</​code>​
  
-Need to check .htaccess ​for those rules. Finally identified that the following rewrite rules break litemage ESI. The solution is add conditions to exclude /​litemage/​esi to those rules.  +We look in ''​.htaccess''​ and identify ​the following ​faulty ​rewrite rules: 
- +<​code>​ 
-Faulty rewrite Rules+## Custom Selesti rewrites
- +
-  ## Custom Selesti rewrites +
- +
-    #301 redirect if pagination is on page 1 in query string +
-    RewriteCond %{QUERY_STRING} p=1 +
-    RewriteRule ^(.*)$ %{REQUEST_URI}?​ [R=301,L]+
  
-    RewriteCond %{REQUEST_FILENAME} !-f +#301 redirect if pagination is on page 1 in query string 
-    RewriteCond %{REQUEST_URI!(\.gif|\.png|\.jpg|\.jpeg|\.css|\.js)$ [NC] +RewriteCond %{QUERY_STRINGp=1 
-    RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest +RewriteRule ^(.*)$ %{REQUEST_URI}[R=301,L]
-    RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ +
-    RewriteCond %{REQUEST_URI} !(.*)/$ +
-    RewriteRule ^(.*)$ ​http://%{HTTP_HOST}/$1/ [L,R=301]+
  
-    ​RewriteCond %{REQUEST_URI[A-Z] +RewriteCond %{REQUEST_FILENAME!-f 
-    RewriteCond %{REQUEST_URI} !^/(media|skin|js|customer|checkout|sgps|ajaxcart|themeframework|wishlist|)/ +RewriteCond %{REQUEST_URI} !(\.gif|\.png|\.jpg|\.jpeg|\.css|\.js)$ [NC] 
-    RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest +RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest 
-    RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ +RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ 
-    RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_URI} !(.*)/$ 
-    RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ​^(.*)$ http://%{HTTP_HOST}/$1[L,R=301]
-    RewriteCond %{REQUEST_FILENAME} !-l +
-    RewriteRule (.*) ${lc:$1[R=301,L]+
  
-Solutions ​to exclue ​litemage ​URL from the rewrite. ​+RewriteCond %{REQUEST_URI} [A-Z] 
 +RewriteCond %{REQUEST_URI} !^/​(media|skin|js|customer|checkout|sgps|ajaxcart|themeframework|wishlist|)/​ 
 +RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest 
 +RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ 
 +RewriteCond %{REQUEST_FILENAME} !-f 
 +RewriteCond %{REQUEST_FILENAME} !-d 
 +RewriteCond %{REQUEST_FILENAME} !-l 
 +RewriteRule (.*) ${lc:$1} [R=301,L] 
 +</​code>​ 
 +We can solve this problem by adding conditions ​to those rules that will exclude ''/​litemage/​esi'':​ 
 +<​code>​
 ## Custom Selesti rewrites ## Custom Selesti rewrites
  
-    ​#301 redirect if pagination is on page 1 in query string +#301 redirect if pagination is on page 1 in query string 
-    RewriteCond %{QUERY_STRING} p=1 +RewriteCond %{QUERY_STRING} p=1 
-    RewriteRule ^(.*)$ %{REQUEST_URI}?​ [R=301,L]+RewriteRule ^(.*)$ %{REQUEST_URI}?​ [R=301,L]
  
-    ​RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-f 
-    RewriteCond %{REQUEST_URI} !(\.gif|\.png|\.jpg|\.jpeg|\.css|\.js)$ [NC] +RewriteCond %{REQUEST_URI} !(\.gif|\.png|\.jpg|\.jpeg|\.css|\.js)$ [NC] 
-    RewriteCond %{REQUEST_URI} !litemage +RewriteCond %{REQUEST_URI} !litemage 
-    RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest +RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest 
-    RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ +RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ 
-    RewriteCond %{REQUEST_URI} !(.*)/$ +RewriteCond %{REQUEST_URI} !(.*)/$ 
-    RewriteRule ^(.*)$ http://​%{HTTP_HOST}/​$1/​ [L,R=301]+RewriteRule ^(.*)$ http://​%{HTTP_HOST}/​$1/​ [L,R=301]
  
-    ​RewriteCond %{REQUEST_URI} [A-Z] +RewriteCond %{REQUEST_URI} [A-Z] 
-    RewriteCond %{REQUEST_URI} !^/​(media|skin|js|customer|checkout|sgps|ajaxcart|themeframework|wishlist|)/​ +RewriteCond %{REQUEST_URI} !^/​(media|skin|js|customer|checkout|sgps|ajaxcart|themeframework|wishlist|)/​ 
-    RewriteCond %{REQUEST_URI} !litemage +RewriteCond %{REQUEST_URI} !litemage 
-    RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest +RewriteCond %{HTTP:​X-Requested-With} !=XMLHttpRequest 
-    RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ +RewriteCond %{HTTP:​X-REQUESTED-WITH} !^(XMLHttpRequest)$ 
-    RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-f 
-    RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-d 
-    RewriteCond %{REQUEST_FILENAME} !-l +RewriteCond %{REQUEST_FILENAME} !-l 
-    RewriteRule (.*) ${lc:$1} [R=301,L]+RewriteRule (.*) ${lc:$1} [R=301,L] 
 +</​code>​
  
-Problem ​ResolvedError message gone.+Problem ​solvedThe error message ​is gone, and the ESI requests are being correctly sent to the Magento backend.
 {{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​an-error-occurred-while-processing-this-directive-fix.png?​800 |}} {{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​an-error-occurred-while-processing-this-directive-fix.png?​800 |}}
  
  • Admin
  • Last modified: 2017/05/11 21:46
  • by Jackson Zhang