fix(openlitespeed): autoLoadHtaccess 挪到 vhost 级

这个选项只在 vhost 级的 rewrite 块里生效,写进 context 会被静默忽略,
WordPress 这类自己维护 .htaccess 的应用规则全部不生效,固定链接只能退回 index.php 形式。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
耗子
2026-09-23 10:23:34 -07:00
co-authored by Claude Opus 5.5
parent d51485bcf9
commit 3c9f0d1e9b
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -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() {
+13
View File
@@ -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"))
}