{host} in rewrite no work

Hi,

I am trying to use {host} in rewrite but not work.

Caddyfile:

* {
    root ./
    fastcgi / 127.0.0.1:9000 php
    rewrite {
        to {path}/{host} {path}/{host}/ /index.php?{query}
    }
    tls off
}

When i try access in browser “http://something/” the result is “No input file specified.”.

Log file say this:

[ERROR 0 /index.php] Unable to open primary script: /var/www/index.php (No such file or directory)

My Caddyfile location: “/var/www”.

anyone can help me?

Sounds to me like rewrite is actually working perfectly. Your usage of placeholders seems a little odd, though. When dealing with a request for http://something/, in this instance:

  • {path} is /
  • {host} is something
  • {query} is empty

Your rewrite tries the following three requests, in order, until one works:

  • {path}/{host} effectively becomes http:///something - this will probably wig out entirely on the triple slash, but may instead look for an index file in the document root and fail on that;
  • {path}/{host} becomes http:///something/, not much better;
  • /index.php?{query} becomes http://something/index.php?

My guess is your document root has no index files (and no index.php), so when Caddy gets to step 3 there it tries to fob the problem off on fastcgi, which tells you straight up there’s no index file.

Thanks for the answer,

I trying configure caddy for my Laravel’s projects, so, with your tips, i changed my Caddyfile to this:

*:80 {
    root ./
    fastcgi / 127.0.0.1:9000 php
    rewrite {
        to {path}{host}/public {path}{host}/public/ /index.php?{query}
    }
    tls off
}

it’s works, but only for “/” request, if resquest is for “/anything” not works, like css, js, images and others requests.

the log error:
127.0.0.1 - [06/Dec/2016:12:14:31 -0300] "GET /index.php HTTP/1.1" 404 25

What do I have to do to solve this?

This is a 404 error. Caddy (or fastcgi) can’t find an index.php to serve for the request. Either there is no index.php in the document root, or the permissions are set such that Caddy can’t read it.

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