【问题标题】:Converting .htaccess to lighttpd for a subdirectory将 .htaccess 转换为子目录的 lighttpd
【发布时间】:2019-10-21 09:31:51
【问题描述】:

我是新手,正在尝试将 htaccess 转换为 lighttpd 格式,但我尝试的一切都不起作用。 我对 example.com 有一些规则,现在我想添加一个名为 /test 的新子目录,并仅为该目录使用 htaccess 规则(这甚至可能吗?)。 无论如何,这是我要转换的 htaccess:

Options +FollowSymlinks

RewriteRule ^.*\.(gif|png|jpe?g|bmp|css|js|swf|wav|avi|mpg|ttf|woff)$ - [NC,L]

RewriteRule ^dashboard/ - [R=403,L,NC]
RewriteRule ^admin/ - [R=403,L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.sa$ index.php?sa=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [PT,L]

现在,我的猜测解决方案是这样的,但它不起作用,我不明白如何使它起作用:

   $HTTP["url"] =~ "^/test" {
$HTTP["url"] !~ "^/(dashboard|admin)/" {
    url.access-deny = ("")
}
url.rewrite-if-not-file = (
    "^/(.*)$" => "/index.php?uri=$1",
    "^/(.*/).sa$" => "index.php?sa=$1",
)
server.follow-symlink = "enable"}

有人可以帮忙吗? 谢谢

【问题讨论】:

    标签: .htaccess mod-rewrite lighttpd


    【解决方案1】:

    lighttpd 重写规则匹配完整的 url 路径 + 查询字符串,而 $HTTP["url"] 只是 url 路径(是的,我可以看到这可能有点令人困惑)而 $HTTP["query-string"] 只是查询-字符串。

    以下使用 lighttpd 1.4.50(一年多前发布)中可用的一些语法当前版本的 lighttpd 是 lighttpd 1.4.54。 (例如,如果您使用的是 lightttpd 1.4.45,那么您的发行版会落后一点)

    $HTTP["url"] !~ "^/(dashboard|admin)/" {
        url.access-deny = ("")
    }
    $HTTP["url"] !~ "\.(?i:gif|png|jpe?g|bmp|css|js|swf|wav|avi|mpg|ttf|woff)$" {
        url.rewrite-if-not-file = (
            "^(/.*)\.sa(\?.*)?$" => "index.php?sa=$1${qsa}",
            "" => "/index.php?uri=${url.path}${qsa}",
        )
    }
    server.follow-symlink = "enable"
    

    【讨论】:

    • 嗯,它不起作用,现在整个规则都适用于 example.com,而不仅仅是 example.com/test。而且重写不是重写 url(意味着 example.com /test/install 不会给出 example.com/test/index.php?uri=install 或 example.com/test/data.sa 不会给出 example.com/test/index.php?sa=data
    • 您在原始帖子中提供的正则表达式永远不会同时匹配,因为它们都锚定在字符串的开头:` $HTTP["url"] =~ "^/test" { $HTTP ["url"] !~ "^/(dashboard|admin)/" ...`。因此,我认为你犯了一个明显的错误。如果要添加外部条件,请继续,并确保调整内部正则表达式。关于你评论的第二部分,我认为你很困惑。内部重写 (mod_rewrite) 和外部重定向 (mod_redirect) 之间存在差异。
    猜你喜欢
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 2020-03-14
    相关资源
    最近更新 更多