Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
litespeed_wiki:config:internal-redirect [2018/09/27 21:09] Jackson Zhang [Set header "X-LiteSpeed-Location" in your php script] |
litespeed_wiki:config:internal-redirect [2018/09/27 21:13] Jackson Zhang |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Internal Redirect ====== | ====== Internal Redirect ====== | ||
- | Web server internal redirect via backend response header, aka X-Sendfile or X-Accel-Redirect, is a feature used by some web backend developers and popularized by Ruby on Rails. LSWS and OLS use a simple header "X-LiteSpeed-Location" to achieve the same goal. | + | Web server internal redirect via backend response header, aka X-Sendfile or X-Accel-Redirect, is a feature used by some web backend developers and popularized by Ruby on Rails. LSWS and OLS use a simple header "Location" or "X-LiteSpeed-Location" to achieve the same goal. |
===== What is this internal redirect via response header? ===== | ===== What is this internal redirect via response header? ===== | ||
Line 11: | Line 11: | ||
The end user is not aware of this internal redirection and the data returns appears from the original url. | The end user is not aware of this internal redirection and the data returns appears from the original url. | ||
- | ===== Implemente internal redirect on LiteSpeed through header "X-LiteSpeed-Location" ===== | + | ===== Implemente internal redirect on LiteSpeed through header ===== |
To get this to work on LiteSpeed, just use a simple header "X-LiteSpeed-Location" in your php script. | To get this to work on LiteSpeed, just use a simple header "X-LiteSpeed-Location" in your php script. | ||
- | ==== Set header "Location" in your php script ==== | + | ==== Method 1: Set header "Location" in your php script ==== |
Set "**Location**" header pointing to a URL without ''<nowiki>http://domain</nowiki>'', just the URL without the hostname part. Do not set a "**Status**" header in response. Make sure no "Status" header is returned. PHP always adds "**Status**" header automatically when a "**Location**" header was set. | Set "**Location**" header pointing to a URL without ''<nowiki>http://domain</nowiki>'', just the URL without the hostname part. Do not set a "**Status**" header in response. Make sure no "Status" header is returned. PHP always adds "**Status**" header automatically when a "**Location**" header was set. | ||
Line 23: | Line 23: | ||
?> | ?> | ||
- | ==== Set header "X-LiteSpeed-Location" in your php script ==== | + | ==== Method 2: Set header "X-LiteSpeed-Location" in your php script ==== |
- | Add a special header "**X-LiteSpeed-Location**" starting from LSWS 3.0.2 to address this, just use it in the same way as a "**Location**" header. For example, just put a line like below to the php script: | + | Add a special header "**X-LiteSpeed-Location**" starting from LSWS 3.0.2 to address this, just use it in the same way as a "**Location**" header and it is the recommended way to implement Internal Redirect on LSWS. |
+ | |||
+ | For example, put a line like below to the php script: | ||
header('X-LiteSpeed-Location: /path/to/file_to_be_redirected'); | header('X-LiteSpeed-Location: /path/to/file_to_be_redirected'); | ||
- | **Note:** "/path/to/file_to_be_redirected" should be URL without http://domain but with "/", such as: **test.php** in document root: | + | **Note:** "/path/to/file_to_be_redirected" should be URL without http://domain but with "/", such as: **test.php** in document root. LSWS only supports "URL" instead of "file path". |
<?php | <?php | ||
header('X-LiteSpeed-Location: /img/php-icon.png'); | header('X-LiteSpeed-Location: /img/php-icon.png'); | ||
?> | ?> | ||
- | That's it folks. LiteSpeed will take over the the rest, perform an internal redirect, and send back the file with sendfile() support if the url points to a static file. | + | That's it, folks. LiteSpeed will take over the rest, perform an internal redirect, and send back the file with sendfile() support if the URL points to a static file. |
Run a test through | Run a test through |