子目录中不同的lighttpd重写规则 [英] Different lighttpd rewrite rules in subirectory
问题描述
我在获取特定子目录(不同于 webroot)的重写规则时遇到了一些问题,我不知道将它们放在哪里.
I'm having a few issues getting rewrite rules for a specific subdirectroy (different from the webroot) and I'm at a loss as to where to put them.
/var/www/(包含 WordPress 的 webroot)/var/www/subdirectory(包含其他需要自己重写规则的应用)
/var/www/ (webroot containing WordPress) /var/www/subdirectory (containing other app which requires it's own rewrite rules)
以下规则适用于位于 webroot 目录中的 WordPress(/var/www,或 http://mywebsite.com):
The below rules I for WordPress which is in the webroot dir (/var/www, or http://mywebsite.com):
$HTTP["host"] =~ "mywebsite.com" {
url.rewrite-final = (
# Exclude some directories from rewriting
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
# Exclude .php files at root from rewriting
"^/(.*.php)" => "$0",
# Handle permalinks and feeds
"^/(.*)$" => "/index.php/$1"
)
}
然后我有第二个应用程序,它位于 webroot 的子目录(/var/www/subdirectory,或 http://mywebsite.com/subdirectory) 并遵循以下规则:
Then I have a second app that sits in a subdirectory of the webroot (/var/www/subdirectory, or http://mywebsite.com/subdirectory) with the following rules:
url.rewrite = (
"(index.php|test.php|favicon.ico)" => "/$1",
"(css|files|img|js)/(.*)" => "/$1/$2",
"^([^?]*)(?(.+))?$" => "/index.php?url=$1&$3",
)
我需要的是将上述第一组重写规则应用于除上述#Excluded 规则(以及/subdirectory)中的其他目录之外的所有内容,然后第二组规则仅应用于/subdirectory
What I need is for the 1st set of rewrite rules above applied to everything except the other directories in the #Excluded rule above (as well as /subdirectory) then the 2nd set of rules applied to only /subdirectory
我从网上某处的博客中获得了第一组 WordPress 规则,任何可能都不是我所需要的(关于匹配mywebsite.com",可能可以简化).
I got the first set of rules for WordPress from a blog somewhere online any may well be not exactly what I need (in regards to matching "mywebsite.com" and could probably be simplified).
我已经在谷歌上尝试了多种变体(主要是在稍微相关的随机论坛帖子的指导下在黑暗中刺伤),但我就是无法理解它.
I've Googled myself out trying multiple variations (mostly just stabbing in the dark guided by random forum posts that are slightly related), but I just can't wrap my head round it.
那么我将如何将第二组规则应用于子目录,同时维护根目录的 Wordpress 规则?
So how would I go about having the 2nd set of rules applied to the subdirectory while maintaining the Wordpress rules for the root?
注意:我无法访问子域(那太容易了).
Note: I have no access to subdomains (that would be too easy).
推荐答案
我不太确定你想表达什么 - 我会解释你当前的规则集是做什么的.
I am not quite sure what you want to express - I will explain what your current ruleset does.
不要使用这个,而是用户重写一次
do not use this, user rewrite-once instead
url.rewrite = (
您将任何 index.php 和 test.php(甚至 foo-test.php)映射回 webroot
you keep map any index.php and test.php (even foo-test.php) back to the webroot
"(index.php|test.php|favicon.ico)" => "/$1",
您将任何包含 css、files、tmp 或 js 的子文件夹或文件重写到 webroot 的 url 中
you rewrite any subfolder or files containing css,files,tmp or js in it's url back to the webroot
"(css|files|img|js)/(.*)" => "/$1/$2",
现在这匹配您的 webroot 中的任何内容(没有子目录!)并保持获取请求
now this matches anything in the your webroot (no subdirs!) and keeps get requests
"^([^?]*)(?(.+))?$" => "/index.php?url=$1&$3",
)
更新这应该可以(未经测试)
Update This should do it (untested)
url.rewrite-once = (
"^/subdir/(?:index.php|test.php|favicon.ico)" => "$0",
"^/subdir/(?:.+/)?(css|files|img|js)/(.*)" => "/subdir/$1/$2", #update #2
"^/subdir/(?:/(?:.+/))?([^?]*)(?:?(.+))?$" => "/subdir/index.php?url=$1&$2",
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
"^/(.*.php)" => "$0",
"^/(.*)$" => "/index.php/$1"
)
这篇关于子目录中不同的lighttpd重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!