Differences

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

Link to this comparison view

Next revision Both sides next revision
litespeed_wiki:config:multiviews [2015/07/24 15:43]
Michael Alegre created
litespeed_wiki:config:multiviews [2018/09/12 20:53]
Jackson Zhang
Line 1: Line 1:
 ====== How to enable Multiviews ====== ====== How to enable Multiviews ======
  
-MultiViews is an Apache per-directory option, which is not naively ​supported by LiteSpeed web server at the time of this writing. However it can be achieved through rewrite rule. +MultiViews is an Apache per-directory option, which is not natively ​supported by LiteSpeed web server at the time of this writing. Howeverit can be achieved through ​the rewrite ​rules.  
 + 
 +===== What's Apache Multiviews ===== 
 + 
 +The effect of MultiViews is as follows: if the server receives a request for /​some/​dir/​foo,​ if /some/dir has MultiViews enabled, and /​some/​dir/​foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client'​s requirements. 
 + 
 +MultiViews may sometimes cause very strange rewrite problem. When you turn on rewrite log, you might see something like the following. It indicates "​MultiViews"​ is enabled.  
 + 
 +  [perdir /var/www/] add path info postfix: /​var/​www/​product.php -> /​var/​www/​product.php/​Test__Test.php 
 +  [perdir /var/www/] strip per-dir prefix: /​var/​www/​product.php/​Test__Test.php -> product.php/​Test__Test.php 
 +  [perdir /var/www/] applying pattern '​^([0-9]+)/​([^/​]+)\.php$'​ to uri '​product.php/​Test__Test.php'​ 
 +  [perdir /var/www/] add path info postfix: /​var/​www/​product.php -> /​var/​www/​product.php/​Test__Test.php 
 +  [perdir /var/www/] strip per-dir prefix: /​var/​www/​product.php/​Test__Test.php -> product.php/​Test__Test.php 
 +  [perdir /var/www/] applying pattern '​^prodotto/​([^/​]+)\.php$'​ to uri '​product.php/​Test__Test.php'​ 
 +  [perdir /var/www/] add path info postfix: /​var/​www/​product.php -> /​var/​www/​product.php/​Test__Test.php 
 +  [perdir /var/www/] strip per-dir prefix: /​var/​www/​product.php/​Test__Test.php -> product.php/​Test__Test.php 
 +  [perdir /var/www/] applying pattern '​^prodotto/​([^/​]+)\.php?​id=([0-9]+)$'​ to uri '​product.php/​Test__Test.php'​ 
 +  [perdir /var/www/] add path info postfix: /​var/​www/​product.php -> /​var/​www/​product.php/​Test__Test.php 
 +  [perdir /var/www/] strip per-dir prefix: /​var/​www/​product.php/​Test__Test.php -> product.php/​Test__Test.php 
 +  [perdir /var/www/] applying pattern '​^c/​([^/​]+)/​([^/​]+)\.php$'​ to uri '​product.php/​Test__Test.php'​ 
 +  [perdir /var/www/] pass through /​var/​www/​product.php  
 + 
 +The problem was that the request was being modified by MultiViews, substituting /product/ with /​product.php and never triggering the mod_rewrite ​rule. 
 + 
 +Generally we don't recommend to use MultiViews function to avoid such confistion. 
 + 
 +===== Example 1 in real life when URI using pathinfo ===== 
 +Our customer is using an old jshop which works on Apache. After switch to LSWS, it always redirect to the homepage. It has a very very long rewrite in .htaccess hence it is not easy to identify where is wrong. 
 + 
 +Enable rewrite log for Apache and LSWS, but it still not easy to identify the problem.  
 + 
 +The following is from Apache rewrite log: 
 + 
 +  [Wed Sep 12 05:​46:​58.807252 2018] [rewrite:​trace3] [pid 679517:tid 140344885401344] mod_rewrite.c(483):​ [client 175.156.215.157:​58596] 175.156.215.157 - - [www.example.com/​sid#​7fa4b3f8b5d8][rid#​7fa460006a60/​initial] [perdir /​home/​user1/​public_html/​] add path info postfix: /​home/​user1/​public_html/​s.php -> /​home/​user1/​public_html/​s.php/​2/​menus-reading-michelin-star-restaurant-berkshire,​ referer: https://​www.example.com/​ 
 +  [Wed Sep 12 05:​46:​58.807300 2018] [rewrite:​trace3] [pid 679517:tid 140344885401344] mod_rewrite.c(483):​ [client 175.156.215.157:​58596] 175.156.215.157 - - [www.lortolan.com/​sid#​7fa4b3f8b5d8][rid#​7fa460006a60/​initial] [perdir /​home/​user1/​public_html/​] strip per-dir prefix: /​home/​user1/​public_html/​s.php/​2/​menus-reading-michelin-star-restaurant-berkshire -> s.php/​2/​menus-reading-michelin-star-restaurant-berkshire,​ referer: https://​www.example.com/​ 
 + 
 +As far as the following MultiViews option disabled in .htaccess, Apache won't work anymore.  
 +  Options +MultiViews 
 + 
 +It can be determined that MultiViews is the root cause for the rewrite problem.  
 + 
 +Why Apache works but LSWS doesn'​t?​ Apache supports the above MultiViews while LSWS does not. How to make MultiViews work on LSWS? 
 + 
 +If a site has a URI that uses PATHINFO, here's how the redirection should work: 
 +  /​topic/​Office/​Work ==> /​topic.php/​Office/​Work 
 +  /​update/​Office/​Work ==> /​update.php/​Office/​Work/​topic->​ /​topic.php 
 + 
 +The following is a code example to implement Multiviews that uses PATHINFO through rewrite rules for LSWS: 
 + 
 +  # Multiviews example code...use this in a .htaccess file 
 +  RewriteEngine On 
 +  RewriteCond %{REQUEST_URI} !.+php* 
 +  RewriteCond %{DOCUMENT_ROOT}/​$1\.php -f 
 +  RewriteRule ^([^/​]+)/?​(.*)$ $1.php/$2 [L] 
 + 
 +As far as the above code added, LSWS works fine now for this particular site. 
 + 
 +===== Example 2 ===== 
  
 For example: For example:
  • Admin
  • Last modified: 2018/09/13 15:13
  • by Lisa Clarke