如何让LiteSpeed像apache2一样评估.htaccess中的所有重写规则?
我遇到了 LiteSpeed 没有以与 apache2 相同的方式评估 mod_rewrite 规则的问题
我有一个 php 路由系统,其 mod_rewrite 设置重写 http ://example.com/page-name 到 http://example.com/ index.php/page-name 与$_SERVER['REQUEST_URI']。这很好用。
我现在添加了一个 URI,用于从名为 ex http 的图像 URI 生成缩略图://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg。此 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]
I have problems with LiteSpeed not evaluating mod_rewrite rules the same way as apache2
I have a php routing system with a mod_rewrite setting that rewrites http://example.com/page-name to http://example.com/index.php/page-name with $_SERVER['REQUEST_URI']. This works fine.
I have now added a URI to generate thumbnails from an image URI called ex http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg. This URL generates a thumbnail image that is saved to http://example.com/images/thumbnail/1.jpg to enable caching.
The next step is a regexp that checks if an image at http://example.com/images/thumbnail/1.jpg and if not runs http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg to generate a new thumbnail.
The .htaccess file below works great in apache2 but does not work at my hosting service that runs LiteSpeed. On LiteSpeed only the first rewrite rules is evaluated so that if http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg does not exist the server seem to look for the file http://example.com/generate-thumbnail instead of evaluating the last rewrite rules that would result in the correct URL http://example.com/index.php/generate-thumbnail?uri=/images/thumbnails/1.jpg.
apache2 get this right but not LiteSpeed, why?
If I change the RewriteRule (.*) /generate-thumbnail?uri=$1 [L]
to RewriteRule (.*) /file_that_exists.php?uri=$1 [L]
where file_that_exists.php is a real file, everything works fine in LiteSpeed.
How can I get LiteSpeed to evaluate all the rewrite rules?
# 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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
[LAST]
标志,mod_rewrite 也应该停止在/generate-thumbnail
规则处。如果您确实希望也应用index.php/
规则,请删除该[L]
。由于 LiteSpeed 声称与 Apache 兼容,我猜测它是一个商业分支。如果是这样,我不明白它怎么会转移到这里。但无论如何,启用
RewriteLog
否则可以找到原因。mod_rewrite too should stop at the
/generate-thumbnail
rule due to the[LAST]
flag. Remove that[L]
if you actually want theindex.php/
rule to apply as well.Since LiteSpeed claims compatibility with Apache, I would surmise it's a commercial fork. If so, I don't understand how it could divert here. But anyway, enable the
RewriteLog
otherwise to find the cause.