Rewrite rule not working

I’m sure this is my fault and not Caddy’s so this is not a bug report, more like a help request. I have this website that I’m porting to a community software (ipb) and I placed Caddy in front. The old website had a separate app (Ghost) that was sitting at /blog. This new community software has a blog app of it’s own and I want to write some rewrites or permanent redirects for the old content which is getting a decent amount of traffic.

My approach was to redirect these posts one by one because I’m only talking about 20 of them. The first post that I tested is sitting at /blog/hedging/ on the old url and at /index.php?app=blog&module=blogs&controller=entry&id=2 on the new app so this is what I ended up with.

forum.typely.com {
        root /var/www/
        log /var/log/caddy.log

        rewrite /blog/hedging/ /index.php?app=blog&module=blogs&controller=entry&id=2

        rewrite / {
                to {path} {path}/ /index.php?{query}
        }

        fastcgi / 127.0.0.1:9000 php
}

I also tried the rewrite with a redirect redir /blog/hedging/ /index.php?app=blog&module=blogs&controller=entry&id=2 301 without any luck. I get a 404 on the CMS all the time. If I test the url in the browser directly (/index.php?app=blog&module=blogs&controller=entry&id=2) it works without issues.

Any ideas?

Figured it out, as always, after posting this thread:

forum.typely.com {
        root /var/www/
        log /var/log/caddy.log

        redir /blog/hedging/ /index.php?app=blog&module=blogs&controller=entry&id=2 301

        rewrite / {
                if {path} not /blog/hedging/
                to {path} {path}/ /index.php?{query}
        }

        fastcgi / 127.0.0.1:9000 php
}
1 Like

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