From 3c9f0d1e9b0dcaee0f9dc7cafe8def42e604d85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Wed, 23 Sep 2026 10:23:34 -0700 Subject: [PATCH] =?UTF-8?q?fix(openlitespeed):=20autoLoadHtaccess=20?= =?UTF-8?q?=E6=8C=AA=E5=88=B0=20vhost=20=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这个选项只在 vhost 级的 rewrite 块里生效,写进 context 会被静默忽略, WordPress 这类自己维护 .htaccess 的应用规则全部不生效,固定链接只能退回 index.php 形式。 Co-Authored-By: Claude Opus 5.5 --- pkg/webserver/openlitespeed/vhost.go | 2 +- pkg/webserver/openlitespeed/vhost_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/webserver/openlitespeed/vhost.go b/pkg/webserver/openlitespeed/vhost.go index 1f20db68d..2d4ad5714 100644 --- a/pkg/webserver/openlitespeed/vhost.go +++ b/pkg/webserver/openlitespeed/vhost.go @@ -589,7 +589,6 @@ func (v *baseVhost) buildRootContext(cfg *conf.Config, consumed map[int]bool) { ctx.Add("allowBrowse", "1") rw := ctx.AddBlock("rewrite", "") rw.Add("enable", "1") - rw.Add("autoLoadHtaccess", "1") for i, auth := range v.auths { if auth.Path == "/" && !consumed[i] { ctx.Add("realm", v.realmName(i)) @@ -702,6 +701,7 @@ func (v *baseVhost) buildIncludes(cfg *conf.Config) []string { func (v *baseVhost) buildRewrite(cfg *conf.Config, fragments []string) { rw := cfg.AddBlock("rewrite", "") rw.Add("enable", "1") + rw.Add("autoLoadHtaccess", "1") // OLS 核心对 /.well-known/acme-challenge/ 强制跳过 rewrite,无需排除验证路径 if !v.Enable() { diff --git a/pkg/webserver/openlitespeed/vhost_test.go b/pkg/webserver/openlitespeed/vhost_test.go index c258bf3de..fbdfcf9b3 100644 --- a/pkg/webserver/openlitespeed/vhost_test.go +++ b/pkg/webserver/openlitespeed/vhost_test.go @@ -356,3 +356,16 @@ func TestProxyAuthContext(t *testing.T) { check.DeepEqual(t, vhost.BasicAuth(), []types.BasicAuth{{Path: "/secret", UserFile: filepath.Join(configDir, "htpasswd_0")}}, cmpopts.EquateEmpty()) } + +// autoLoadHtaccess 只在 vhost 级生效,写进 context 会被 OLS 静默忽略 +func TestHtaccessAtVhostLevel(t *testing.T) { + configDir := newConfigDir(t) + vhost, err := NewPHPVhost(configDir) + must.NoError(t, err) + must.NoError(t, vhost.Save()) + + cfg, err := Parse(readConf(t, configDir)) + must.NoError(t, err) + check.Equal(t, cfg.GetBlock("rewrite").Value("autoLoadHtaccess"), "1") + check.Empty(t, cfg.GetBlock("context", "/").GetBlock("rewrite").Value("autoLoadHtaccess")) +}