Running Selfoss with caddy (htaccess conversion)

Hi,

I’m trying to run selfoss with caddy and as selfoss wasn’t designed to work with it, it only provides a .htaccess. I tried to convert it myself but it hasn’t been a successful enterprise. Therefore I’m turning to this forum for help converting it.

# Enable rewrite engine and route requests to framework
RewriteEngine On
#RewriteBase /selfoss

# rule for ACME
RewriteRule .well-known/(.*) - [L]

# rule for favicons
RewriteRule !data/favicons/(.*)$ - [C]
RewriteRule favicons/(.*)$ data/favicons/$1 [L]

# rule for thumbnails
RewriteRule !data/thumbnails/(.*)$ - [C]
RewriteRule thumbnails/(.*)$ data/thumbnails/$1 [L]

# rule for front controller
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule !.(js|ico|gif|jpg|png|css|asc|txt|eot|woff|ttf|ttf|svg|xml)$ index.php?%1

# rule for files
RewriteRule !favicons/ - [C]
RewriteRule !thumbnails - [C]
RewriteRule !public - [C]
RewriteRule !index.php - [C]
RewriteRule (.*) public/$1 [L]

# set magic_quotes_gpc as f3 wouldn't start otherwise
<IfModule mod_php5.c>
    php_value magic_quotes_gpc "1"
</IfModule>

# deny requests for config files
<FilesMatch ".(ini)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Disable ETags
<IfModule mod_headers.c>
    Header Unset ETag
    FileETag none
</IfModule>

# Default expires header if none specified (stay in browser cache for 7 days)
<IfModule mod_expires.c>

    ExpiresActive on
    ExpiresDefault                                      "access plus 1 week"

  # CSS
    ExpiresByType text/css                              "access plus 1 year"

  # Data interchange
    ExpiresByType application/json                      "access plus 0 seconds"
    ExpiresByType application/xml                       "access plus 0 seconds"
    ExpiresByType text/xml                              "access plus 0 seconds"

  # Favicon (cannot be renamed!)
    ExpiresByType image/x-icon                          "access plus 1 week"

  # HTML components (HTCs)
    ExpiresByType text/x-component                      "access plus 1 month"

  # HTML
    ExpiresByType text/html                             "access plus 0 seconds"

  # JavaScript
    ExpiresByType application/javascript                "access plus 1 year"

  # Manifest files
    ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
    ExpiresByType text/cache-manifest                   "access plus 0 seconds"

  # Media
    ExpiresByType audio/ogg                             "access plus 1 month"
    ExpiresByType image/gif                             "access plus 1 month"
    ExpiresByType image/jpeg                            "access plus 1 month"
    ExpiresByType image/png                             "access plus 1 month"
    ExpiresByType video/mp4                             "access plus 1 month"
    ExpiresByType video/ogg                             "access plus 1 month"
    ExpiresByType video/webm                            "access plus 1 month"

  # Web feeds
    ExpiresByType application/atom+xml                  "access plus 1 hour"
    ExpiresByType application/rss+xml                   "access plus 1 hour"

  # Web fonts
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
    ExpiresByType application/x-font-ttf                "access plus 1 month"
    ExpiresByType font/opentype                         "access plus 1 month"
    ExpiresByType image/svg+xml                         "access plus 1 month"

</IfModule>


<IfModule mod_deflate.c>

    # Force compression for mangled headers.
    # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    # Compress all output labeled with one of the following MIME-types
    # (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
    #  and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
    #  as `AddOutputFilterByType` is still in the core directives).
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE application/atom+xml \
                                      application/javascript \
                                      application/json \
                                      application/rss+xml \
                                      application/vnd.ms-fontobject \
                                      application/x-font-ttf \
                                      application/x-web-app-manifest+json \
                                      application/xhtml+xml \
                                      application/xml \
                                      font/opentype \
                                      image/svg+xml \
                                      image/x-icon \
                                      text/css \
                                      text/html \
                                      text/plain \
                                      text/x-component \
                                      text/xml
    </IfModule>

</IfModule>

# add font types for chromium/chrome
AddType application/font-woff woff

I’m not even sure how much of this is actually pertinent to caddy and what really needs to be converted. I’d be thankful for any help I can get.

That’s a big one.

Try something like this:

example.com {
    rewrite /selfoss {
        r favicons/(.*)$
        to data/favicons/{1}
    }
    rewrite /selfoss {
        r favicons/(.*)$
        to data/thumbnails/{1}
    }
    rewrite /selfoss {
        r .(js|ico|gif|jpg|png|css|asc|txt|eot|woff|ttf|ttf|svg|xml)$
        if {query} match ^(.*)$
        to index.php?{1}
    }
    rewrite /selfoss {
        r (.*)
        if {path} not_match (favicons\/|thumbnails|public|index.php)
        to public/{1}
    }
}

Not quite sure if the 3rd will work or not.

See docs for rewrite

1 Like

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