Process check: Spreading the Caddy Word

Right, time to test out the theory. I set up a test WordPress site. By default, the installation method I use placed the WordPress files in the webroot. Before moving the files to a subdirectory, I made sure I could access various parts of the site. No problems here.

It’s worth noting what appears in the address bar in the second screenshot.

Next, I move the WordPress files into the subdirectory my_subdir. I confirm that I no longer have access to the site
.

I update the site block in the Caddyfile with the code below and reload Caddy.

@subdir {
  not path /my_subdir/*
  not file
}
rewrite @subdir /my_subdir{uri}

Refreshing the browser, the site bursts into life. However, I now have a problem accessing subpages of the site.

There’s some other issue going on. After further research, I find the issue has to do with permalinks. This extract from the WordPress support article Using Permalinks.

When you create or update a “pretty” permalink structure, WordPress will generate rewrite rules and attempt to insert them into the proper .htaccess file. If it can’t, it will say something like You should update your .htaccess now and print out the rules for you to copy and paste into the file (put them at the end).

You’ll probably need to do this only once, because WordPress does the rewriting internally. If you ever move your WordPress home directory (Site address), you’ll need to repeat this step.

I have a look in the permalinks section of the test site and note the following.

A closer look at the rewrite rules…

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Some bits I recognise; some bits I don’t.

I also notice there is the (one and only!) WordPress reference to Caddy in the permalinks article. This extract…

Pretty permalinks are available under:

  • Apache web server with the mod_rewrite module
  • Nginx using try-files, e.g. according to this tutorial
  • Hiawatha web server with UrlToolkit support enabled.
  • Lighttpd using a 404 handler or mod_rewrite
  • Caddy using rewrite, e.g. according to this tutorial

Clicking the link to the tutorial takes me to a Caddy V1 article. (Looks like the WordPress permalinks article is the next one I should try to convert). This is the V1 rewrite rule: I don’t really understand what it’s telling me (e.g. what is this {query} bit?). I’m now stuck again. Help!

    # Routing for WordPress
    rewrite /{
        to {path} {path}/ /index.php?{query}
    }

EDIT: I’ve just made the test site https://xxx.udance.com.au accessible online.

1 Like