1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34# Make subdirectory multisite work under nginx.
#
# WHY THIS FILE IS NEEDED
#
# In a subdirectory network, a sub-site's admin lives at /research/wp-admin/ — but there
# is no folder called research on disk. Apache installs solve this with the .htaccess
# rules WordPress prints for you. nginx does not read .htaccess, so the same rules have
# to be here.
#
# Without this file, the main site works fine and every sub-site's admin 404s, which is
# a confusing way to spend an afternoon.
#
# WHAT THE THREE RULES DO
#
# 1. Add the missing trailing slash to /research/wp-admin.
# 2. Strip the site prefix from any wp-* path, so /research/wp-admin/edit.php is
# served by the real /wp-admin/edit.php.
# 3. Do the same for any other .php file, which covers wp-login.php and friends.
#
# All three are guarded by "does this path not exist on disk?", so a real file is always
# served as itself and never rewritten.
#
# HOW DDEV USES THIS
#
# DDEV copies .ddev/nginx/*.conf into the nginx server block, so this adds to its
# WordPress config rather than replacing it. If you replaced the whole template instead,
# you would own DDEV's TLS and FastCGI setup forever.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}