OpenSupports Htaccess file conversion help needed

I’m trying to run the PHP web application Opensupports with Caddy rather then Apache2 which they have htaccess files for. I don’t quite understand the htaccess files well enough to be able to properly convert them to the caddy rewrite formats.

I’ve tried a few of the Caddy examples without much luck. After that I decided to try and find similar conversions done in other threads and modify them to hopefully achieve what I need, also without success.

Here is the Htaccess file in the web root:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?(api)/
RewriteRule .* index.php [PT,L]

Htaccess file in the /api folder

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [PT,L]

I hope someone can help me convert this htaccess file to the proper format.

Hi @dwaynehulsman, welcome to the Caddy community.

These are actually some of the most common .htaccess files out there. In plain English, they say:

  1. Enable URL rewriting
  2. Only rewrite if the request URI isn’t an actual file
  3. Only rewrite if the request URI isn’t an actual directory
  4. Only rewrite if the request URI doesn’t start with api/ (it might also start with /, too)
  5. Rewrite to /index.php

This behaviour is pretty easily replicable. In a Caddyfile it looks like this:

rewrite {
  if {path} not_starts_with /api/
  to {path} {path}/ index.php
}

Oddly though, the one under the /api folder does the exact same thing. If we remove the not_starts_with check in the above example, it will pull double duty, covering both .htaccess files.

https://caddyserver.com/docs/rewrite

Thanks a lot for your explanation! Although for some reason it’s saying the following: Invalid operator not_starts_with perhaps not_starts_with is deprecated?

Not deprecated, but I believe it was only recently added. Check your Caddy version is up to date.

I’m on Caddy v0.10.3 which is the one you can get here: Download Caddy

not_starts_with is so new, it was added after 0.10.3 – it will be released in the next version. :slight_smile:

1 Like

Ah I see, thanks for the reply!

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