Plz help converting Nginx rewrite to Caddy

Hi guys!
For SuperPWA plugin for Wordpress I need convert nginx rewrites to Caddy rewrites

nginx rewrites

rewrite ^/superpwa-manifest(-[0-9]+)?.json$ /index.php?superpwa-manifest-$1.json last;
rewrite ^/OneSignalSDKWorker.js.php$ /index.php?OneSignalSDKWorker.js-$1.php last;
rewrite ^/superpwa-sw(-[0-9]+)?.js$ /index.php?superpwa-sw.js last;

I tried caddy rules like

rewrite {
    r ^/superpwa-manifest(-[0-9]+)?.json
    to /index.php?superpwa-manifest-{1}.json

rewrite {
    r ^/OneSignalSDKWorker.js.php
    to /index.php?OneSignalSDKWorker.js-{1}.php

rewrite {
    r ^/superpwa-sw(-[0-9]+)?.js
    to /index.php?superpwa-sw.js

But something goes wrong

Can anyone help me with correct caddy rewrite for it?

Hi @nill, welcome to the Caddy community!

Those are interesting rewrites, but you’ve transcribed them faithfully into Caddyfile configuration.

You can use the log directive to help troubleshoot your rewrites. For example:

log / /path/to/caddy.log "{common} // {rewrite_uri}"

Will start to output standard logs appended with the rewritten URI, if a rewrite took place. You can then review the log to make sure the rewritten URI looks like the plugin expects it to. Modify /path/to/caddy.log to specify where you want the logs to be written to.

1 Like

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