Different lighttpd rewrite rules in subirectory

孤人 提交于 2019-12-19 21:45:08

问题


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/ (webroot containing WordPress) /var/www/subdirectory (containing other app which requires it's own rewrite rules)

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"
  )
}

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

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

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.

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).


回答1:


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 = (

you keep map any index.php and test.php (even foo-test.php) back to the webroot

"(index.php|test.php|favicon.ico)" => "/$1",

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


来源:https://stackoverflow.com/questions/12417203/different-lighttpd-rewrite-rules-in-subirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!