Various rules for rewriting lighttpd in a subdirectory

I have several problems rewriting the rules for a specific subdirectory (other than webroot), and I don’t understand where to put them.

/ var / www / (webroot containing WordPress) / var / www / (containing another application that requires its own rewrite rules)

Below are the i rules for WordPress, which are located in the webroot directory (/ 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 application, which is located in the webroot subdirectory (/ 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", ) 

I need the first set of rewrite rules to apply to everything except the other directories in the above #Excluded rule (as well as the / subdirectory), and then the second set of rules that apply only to the / subdirectory

I got the first set of rules for WordPress from a blog somewhere on the Internet, everything may not be exactly what I need (in terms of matching "mywebsite.com" and probably can be simplified).

I searched for myself, trying several options (basically just stabbing in the dark, guided by random forum posts that are a bit related), but I just can't wrap my head around it.

So, how would I use the second set of rules for a subdirectory while saving Wordpress rules for the root?

Note. I do not have access to subdomains (that would be too easy).

+4
source share
1 answer

I'm not quite sure what you want to express - I will explain what your current set of rules does.

don't use this, rewrite user instead

 url.rewrite = ( 

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

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

you rewrite any subfolder or files containing css, files, tmp or js in the url back to webroot

 "(css|files|img|js)/(.*)" => "/$1/$2", 

now it matches anything in your web court (without subdirectors!) and continues to receive 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" ) 
+2
source

Source: https://habr.com/ru/post/1434111/


All Articles