需要帮助为 PHP 路由器形成多个 Lighttpd 条件重定向

问题描述 投票:0回答:1

我正在尝试为 Ubuntu 上的 lighttpd 安装设置一些条件重定向。我想要以下内容:

https://www.example.com/clients/xyz
https://www.example.com/admin/xyz

正常通过,但类似:

https://www.example.com/abc123

重定向到 Web 根目录的“index.php”页面,我将在其中检查 URL 的“abc123”部分并对其进行操作。我希望所有重定向都保留查询参数(如果有)。 我基本上是在构建一个条件路由器,而不会让all请求命中“index.php”。

任何帮助将不胜感激!

我阅读了“lighttpd.conf”中有关“mod_redirect”用法的设置文档,但我很困惑从哪里开始。

php regex routes lighttpd
1个回答
0
投票

我已经有一段时间没有使用 lighttpd 了,但是你可以使用

rewrite-once
匹配你想要的特定内容,然后用
.*
捕获其余的 - 例如

$HTTP["host"] =~ "^www\.example\.com|example.com$" {
    url.rewrite-once = ( 
        "^/clients/(.*)" => "/clients/$1",
        "^/admin/(.*)" => "/admin/$1",
        "^/(.*)" => "/index.php/$1"
    )
}
© www.soinside.com 2019 - 2024. All rights reserved.