Drupal Caddyfile

Does anyone have an example Caddyfile set up for using Drupal? I thought it would be similar to a WordPress one, but the Drupal .htaccess (for 8.3.x, which is the current branch on GitHub) seems rather longer and more complex.

Be nice to have one added to the examples-repo.

I agree, a Drupal example might be nice to have in that repo.

Some of those .htaccess lines won’t really convert over well to Caddyfile. Others are implicit. The rest are mainly rewrite rules or redirects of some sort. (Kind of a shame that a PHP application can’t handle this – IMO this shouldn’t really be the web server’s job when fronting a dynamic application. Oh well.)

This is what I have so far for Drupal 7… note that Clean URLs are not yet working, and I wouldnt try this in production…

http://localhost:8080 {

fastcgi / php

# Set the default handler.
rewrite {
    to {path} {path}/ /index.php?q={query}

# Protect files and directories from prying eyes.
#rewrite {
#    ext engine inc info install make module profile test po sh sql theme tpl.php xtmpl sw bak orig save Repository Root Tag Template php swop

status 404 {

# Make Drupal handle any 404 errors.
errors {
    log error.log
    404 index.php

 # Enable expirations.
expires {
    # Cache all files for 2 weeks after access (A).
    match / 2w

    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    match .php$ 0s

header / {
    X-Content-Type-Options nosniff


1 Like

Has there been any touch-up on clean url with this or Drupal 8?