Rewrite directive not working fully

I just set up a super-simple test with Caddy to get it working on a development server.

My Caddyfile is a single line:

import vhosts/*

Within vhosts I will have separate files for every website I spin up. For now there’s one: Within the file is the following: {
} {
    root /var/www
    fastcgi / /var/run/php/php7.0-fpm.sock php
    rewrite / {
        to {uri} {uri}/ /index.php?_url={uri_escaped}

Within /var/www/index.php is the following:


When I visit in a browser I expect to see:


Instead I see:


What am I doing wrong?

Well, first off, the http->https redirect is done for you automatically; you can leave the scheme off your site address in the Caddyfile.

Your rewrite is trying the URI first, then the URI with a trailing slash, then finally index.php if the file does not exist as one of the first two forms. So I don’t know exactly, but I’d play around with the rewrite a bit.

I should apologize for the wasted time: I found out a day later that Caddy doesn’t check the Caddyfile on every request, but instead loads it when Caddy starts. I thought it was like a .htaccess file so I was just making adjustments and reloading the page without restarting the Caddy service.

Ohh gotcha, glad you figured it out. :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.