亚部门不同的lighttpd重写规则 [英] Different lighttpd rewrite rules in subirectory

查看:72
本文介绍了亚部门不同的lighttpd重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在获取特定子目录(与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)

以下针对WordPress的规则我位于webroot目录(/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).

我已经在Google上尝试了多种变体(大多数情况是,在略有相关的随机论坛帖子的引导下,在黑暗中st了刺),但是我实在无法解决这个问题.

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

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",

现在,它与您的网络根目录中的任何内容匹配(无子目录!),并保持获取请求

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆