Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:config:multiviews [2018/09/12 20:53] Jackson Zhang |
litespeed_wiki:config:multiviews [2018/09/13 15:13] (current) Lisa Clarke Proofreading |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How to enable Multiviews ====== | + | ====== Enabling Multiviews ====== |
- | MultiViews is an Apache per-directory option, which is not natively supported by LiteSpeed web server at the time of this writing. However, it can be achieved through the rewrite rules. | + | MultiViews is an Apache per-directory option, which is not natively supported by LiteSpeed Web Server at the time of this writing. However, it can be achieved through the rewrite rules. |
- | ===== What's Apache Multiviews ===== | + | ===== How Apache Multiviews Works ===== |
- | 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. | + | 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 of 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. | + | MultiViews may sometimes cause a very strange rewrite problem. When you turn on the rewrite log, you might see something like the following, which 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/] add path info postfix: /var/www/product.php -> /var/www/product.php/Test__Test.php | ||
Line 23: | Line 23: | ||
[perdir /var/www/] pass through /var/www/product.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. | + | The problem here is that the request is 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. | + | Generally, to avoid such confusion, we don't recommend using the MultiViews function. |
- | ===== Example 1 in real life when URI using pathinfo ===== | + | ===== Real Life Example 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. | + | Our customer is using an old jshop which works on Apache. After switching to LSWS, it always redirects to the homepage. There is a very very long rewrite in .htaccess, hence it is not easy to identify what is wrong. |
- | The following is from Apache rewrite log: | + | We enable the rewrite log for Apache and LSWS, but it still is not easy to identify the problem. |
+ | |||
+ | The following is from the 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.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/ | [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. | + | We determine that MultiViews is the root cause for the rewrite problem. |
+ | |||
+ | If the following MultiViews option were to be disabled in .htaccess, Apache wouldn't work anymore: | ||
Options +MultiViews | Options +MultiViews | ||
- | It can be determined that MultiViews is the root cause for the rewrite problem. | + | Why does Apache work but LSWS doesn't? Apache supports the above MultiViews while LSWS does not. So how do we make MultiViews work on LSWS? |
- | 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: |
- | + | ||
- | If a site has a URI that uses PATHINFO, here's how the redirection should work: | + | |
/topic/Office/Work ==> /topic.php/Office/Work | /topic/Office/Work ==> /topic.php/Office/Work | ||
/update/Office/Work ==> /update.php/Office/Work/topic-> /topic.php | /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: | + | 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 | + | # Multiviews example code...use this in an .htaccess file |
RewriteEngine On | RewriteEngine On | ||
RewriteCond %{REQUEST_URI} !.+php* | RewriteCond %{REQUEST_URI} !.+php* | ||
Line 56: | Line 57: | ||
RewriteRule ^([^/]+)/?(.*)$ $1.php/$2 [L] | RewriteRule ^([^/]+)/?(.*)$ $1.php/$2 [L] | ||
- | As far as the above code added, LSWS works fine now for this particular site. | + | We added the above code, and now LSWS works fine for this particular site. |
- | + | ||
- | ===== Example 2 ===== | + | |
+ | ===== Multiple Language Example ===== | ||
- | For example: | + | The following is how it's set up with Apache Multiviews: |
<code> | <code> | ||
Line 69: | Line 69: | ||
</code> | </code> | ||
- | can be done through the following rewrite rule: | + | We can get the same effect with LSWS and the following rewrite rules: |
<code> | <code> |