Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:cache:litemage:seperate-mobile-versions-magento [2019/07/10 18:14] Jackson Zhang [Case 1:Rewrite rules should be placed at the top of the .htaccess] |
litespeed_wiki:cache:litemage:seperate-mobile-versions-magento [2019/07/10 19:24] Lisa Clarke Copyediting |
||
---|---|---|---|
Line 9: | Line 9: | ||
-Click on the **Add Exceptions** buttons beside the **Templates**, **Skin** and **Layout** labels. | -Click on the **Add Exceptions** buttons beside the **Templates**, **Skin** and **Layout** labels. | ||
-In the **Value** fields enter the name of your installed mobile theme. | -In the **Value** fields enter the name of your installed mobile theme. | ||
- | -Enter the following line in the **Matched Expression** fields: | + | -Enter the following line in the **Matched Expression** fields: <code>iPhone|iPod|BlackBerry|Palm|Mobile|Opera Mini|Fennec|Windows Phone</code> |
- | + | ||
- | iPhone|iPod|BlackBerry|Palm|Mobile|Opera Mini|Fennec|Windows Phone | + | |
Like so: | Like so: | ||
Line 19: | Line 17: | ||
<code> | <code> | ||
+ | <IfModule LiteSpeed> | ||
+ | RewriteEngine on | ||
RewriteCond %{HTTP_USER_AGENT} "iPhone|iPod|BlackBerry|Palm|Mobile|Opera Mini|Fennec|Windows Phone" | RewriteCond %{HTTP_USER_AGENT} "iPhone|iPod|BlackBerry|Palm|Mobile|Opera Mini|Fennec|Windows Phone" | ||
RewriteRule .* - [E=Cache-Control:vary=ismobile] | RewriteRule .* - [E=Cache-Control:vary=ismobile] | ||
+ | </IfModule> | ||
</code> | </code> | ||
- | **Note1:** Don't add ''[NC]'' to the end of ''RewriteCond'' since in Magento code, the design exception is a regular expression match and is case sensitive. | + | ===== Important Notes ===== |
- | **Note2:** The above rule must be placed on the very top of the .htaccess to avoid other rules stopping its execution. | + | * Don't add ''[NC]'' to the end of ''RewriteCond'' since in Magento code, the design exception is a regular expression match and is case sensitive. |
- | + | * The above rule must be placed at the very top of the .htaccess file to avoid other rules stopping its execution. | |
- | **Important:** Your rewrite rules must //exactly match// your backend's mobile detection (i.e. the string you entered in Step 5 above). If these do not match, your rewrite rules may think that a device is mobile while the backend does not (and vice-versa). This can cause, for example, the desktop version of a page to be cached and flagged as the mobile version which will then be wrongly served to all mobile viewers. | + | * Your rewrite rules must //exactly match// your backend's mobile detection (i.e. the string you entered in Step 5 above). If these do not match, your rewrite rules may think that a device is mobile while the backend does not (and vice-versa). This can cause, for example, the desktop version of a page to be cached and flagged as the mobile version which will then be wrongly served to all mobile viewers. |
====== Troubleshooting ====== | ====== Troubleshooting ====== | ||
- | ===== Case 1:Rewrite rules should be placed at the top of the .htaccess ===== | + | ===== Desktop Version Showing on Mobile ===== |
+ | This case illustrates the importance of placing rewrite rules at the top of the .htaccess file. | ||
- | The user has set up mobile view at Magento 1.8 backend as the following and mobile view is working fine. | + | Let's say you've set up a mobile view in the Magento 1.8 backend, like so, and have verified that the mobile view is working fine. |
{{ :litespeed_wiki:cache:litemage:magento1-mobileview-case.png?nolink&800 |}} | {{ :litespeed_wiki:cache:litemage:magento1-mobileview-case.png?nolink&800 |}} | ||
- | After enabling LiteMage, the user setup rewrite rules in .htaccess with exact matching string with above Magento backend setup, however, desktop version is still showing on mobile with LiteMage. What's wrong with it? | + | After enabling LiteMage, you add rewrite rules to the bottom of your .htaccess file, and use the exact same user agent string that you used above in the Magento backend setup. However, with LiteMage enabled, the desktop version is showing on mobile. Why? |
+ | <IfModule Litespeed> | ||
RewriteEngine on | RewriteEngine on | ||
RewriteCond %{HTTP_USER_AGENT} "android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|iP(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|(Android.+Mobile)|NOKIA|SymbianOS|N900|BlackBerry" | RewriteCond %{HTTP_USER_AGENT} "android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|iP(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|(Android.+Mobile)|NOKIA|SymbianOS|N900|BlackBerry" | ||
RewriteRule .* - [E=Cache-Control:vary=ismobile] | RewriteRule .* - [E=Cache-Control:vary=ismobile] | ||
+ | </IfModule> | ||
+ | |||
+ | **The above rules should have been added to the beginning of .htaccess.** Other rules, like ''RewriteRule .* index.php [L]'', stop the cache rules from being executed. Cache rules should be //always// be placed on the very top of the .htaccess file. | ||
- | By further checking the full .htaccess file, the above rules have been added to the end of .htaccess. Other rules like ''RewriteRule .* index.php [L]'' stopped the cache rules being executed. The cache rule should be always placed on the very top of the .htaccess. After the rules relocated to the top, everything is working fine now. | + | Relocate the rules to the top, like so, and everything works: |
<code> | <code> | ||
<IfModule Litespeed> | <IfModule Litespeed> | ||
- | LiteMage on | + | LiteMage on |
- | </IfModule> | + | |
RewriteEngine on | RewriteEngine on | ||
RewriteCond %{HTTP_USER_AGENT} "android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|iP(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|(Android.+Mobile)|NOKIA|SymbianOS|N900|BlackBerry" | RewriteCond %{HTTP_USER_AGENT} "android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|iP(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|(Android.+Mobile)|NOKIA|SymbianOS|N900|BlackBerry" | ||
RewriteRule .* - [E=Cache-Control:vary=ismobile] | RewriteRule .* - [E=Cache-Control:vary=ismobile] | ||
+ | </IfModule> | ||
############################################ | ############################################ |