1

我有 LiteSpeed 的问题,它没有以与 apache2 相同的方式评估 mod_rewrite 规则

我有一个带有 mod_rewrite 设置的 php 路由系统,它使用 $_SERVER['REQUEST_URI']将http://example.com/page-name重写为http://example.com/index.php/page-name 。这工作正常。

我现在添加了一个 URI,用于从名为 ex http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg的图像 URI 生成缩略图。此 URL 生成一个缩略图图像,该缩略图图像保存到http://example.com/images/thumbnail/1.jpg以启用缓存。

下一步是一个正则表达式,它检查http://example.com/images/thumbnail/1.jpg上的图像是否运行http://example.com/generate-thumbnail?uri=/images/thumbnails/ 1.jpg生成一个新的缩略图。

下面的 .htaccess 文件在 apache2 中运行良好,但不适用于运行 LiteSpeed 的托管服务。在 LiteSpeed 上,仅评估第一个重写规则,因此如果http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg不存在,服务器似乎会查找文件http://example .com/generate-thumbnail而不是评估将导致正确 URL http://example.com/index.php/generate-thumbnail?uri=/images/thumbnails/1.jpg的最后重写规则。

apache2 做到了这一点,但 LiteSpeed 没有做到这一点,为什么?

如果我将文件更改RewriteRule (.*) /generate-thumbnail?uri=$1 [L]RewriteRule (.*) /file_that_exists.php?uri=$1 [L]file_that_exists.php 是一个真实文件的位置,那么在 LiteSpeed 中一切正常。

如何让 LiteSpeed 评估所有重写规则?

# Start the rewrite engine
RewriteEngine On

# Rewrite if post image was requested but is not cached, generate it
RewriteCond %{REQUEST_URI} ^/images/thumbnails/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /generate-thumbnail?uri=$1 [L]

# Rewrite the page into the router
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
4

1 回答 1

1

/generate-thumbnail由于[LAST]标志,mod_rewrite 也应该在规则处停止。[L]如果您确实希望该index.php/规则也适用,请将其删除。

由于 LiteSpeed 声称与 Apache 兼容,我推测它是一个商业分支。如果是这样,我不明白它怎么会转移到这里。但无论如何,启用RewriteLog否则找到原因。

于 2011-06-09T23:14:44.863 回答