At the moment I’m trying to serve sendy.co with Caddyserver.
But sendy.co uses the “mod_rewrite” from apache server.
What do you think is it possible to serve sendy.co with Caddyserver?
The problems are:
mod_rewrite is not enabled
display_errors is turned off
rewrite {
regexp ^/([a-zA-Z0-9-]+)$
to /{1}.php
regexp ^/l/([a-zA-Z0-9/]+)$
to /l.php?i={1}
regexp ^/t/([a-zA-Z0-9/]+)$
to /t.php?i={1}
regexp ^/w/([a-zA-Z0-9/]+)$
to /w.php?i={1}
regexp ^/unsubscribe/(.*)$
to /unsubscribe.php?i={1}
regexp ^/subscribe/(.*)$
to /subscribe.php?i={1}
}
Do I have to tell Caddyfile where the location of sendy is? Because it is in a folder of a hugo site.
Do I have to use “rewrite /sendy” in the Caddyfile?
rewrite /sendy {
regexp ^/([a-zA-Z0-9-]+)$
to /{1}.php
regexp ^/l/([a-zA-Z0-9/]+)$
to /l.php?i={1}
regexp ^/t/([a-zA-Z0-9/]+)$
to /t.php?i={1}
regexp ^/w/([a-zA-Z0-9/]+)$
to /w.php?i={1}
regexp ^/unsubscribe/(.*)$
to /unsubscribe.php?i={1}
regexp ^/subscribe/(.*)$
to /subscribe.php?i={1}
}
Not with those rewrites. You need the capture groups (in parentheses) so you can extract that information and use it in the rewritten URI (those {1}s for example).
Okay, I didn’t know it was in a folder. I went off the nginx configuration you posted.
Try this, assuming it’s in the /sendy folder:
rewrite /sendy {
regexp ^([a-zA-Z0-9-]+)$
to {1}.php
regexp ^l/([a-zA-Z0-9/]+)$
to l.php?i={1}
regexp ^t/([a-zA-Z0-9/]+)$
to t.php?i={1}
regexp ^w/([a-zA-Z0-9/]+)$
to w.php?i={1}
regexp ^unsubscribe/(.*)$
to unsubscribe.php?i={1}
regexp ^subscribe/(.*)$
to subscribe.php?i={1}
}
domain.com {
expires {
match .css$ 1y
match .js$ 1m
match .png$ 1d
match .jpg$ 1m
match .pdf$ 1i
match .txt$ 1s
match .html$ 5i30s
}
minify
header /static/ Cache-Control "max-age=2592000"
gzip
root /var/www/tobias/public # Tells CADDY which folder t$
basicauth /admin xxxxxxxxx xxxxxxxxxxxxxxx # p$
hugo /var/www/tobias # Tells HUGO which folder to e$
fastcgi / /var/run/php/php7.0-fpm.sock php
rewrite /sendy {
regexp ^([a-zA-Z0-9-]+)$
to {1}.php
regexp ^l/([a-zA-Z0-9/]+)$
to l.php?i={1}
regexp ^t/([a-zA-Z0-9/]+)$
to t.php?i={1}
regexp ^w/([a-zA-Z0-9/]+)$
to w.php?i={1}
regexp ^unsubscribe/(.*)$
to unsubscribe.php?i={1}
regexp ^subscribe/(.*)$
to subscribe.php?i={1}
}
}
Looks like they’re not being modified at all. At a guess:
Because URIs always start with a forward slash, and your start-of-line anchor (the ^ symbol) precludes an opening /, those regexes would never match and no rewrites are taking place.
Try add a forward slash just after the start-of-line anchor and test again.
I’d also advise using a site such as https://regexr.com/ to test your regexes before using them.
Wow thank you @Whitestrake now it works with the following rewrites:
rewrite {
r ^/([a-zA-Z0-9-]+)$
to {1}.php
}
rewrite {
r ^/w/([a-zA-Z0-9/]+)$
to w.php?i={1}
}
rewrite {
r ^/l/([a-zA-Z0-9/]+)$
to l.php?i={1}
}
rewrite {
r ^/t/([a-zA-Z0-9/]+)$
to t.php?i={1}
}
rewrite {
r ^/unsubscribe/(.*)$
to unsubscribe.php?i={1}
}
rewrite {
r ^/subscribe/(.*)$
to subscribe.php?i={1}
}