.htaccess rewrite question

1. The problem I’m having:

Im trying to convert a (simple) .htaccess to a caddy file, but i stucked. The original htaccess is the following

RewriteEngine On

RewriteCond %{REQUEST_URI} admin/uploads/.*
RewriteRule ^admin/uploads/(.*)$ uploads/$1 [L]

RewriteCond %{REQUEST_URI} admin/gate/.*
RewriteRule ^admin/gate/(.*)$ gate/$1 [L]

this application is installed in an subdirectory called /map

so i write the following in the Caddyfile

rewrite /map/admin/uploads/(.*) /uploads/{1}
rewrite /map/admin/gate/(.*) /gate/{1}

2. Error messages and/or full log output:

PHP communicaton error

If i use apache it works, so i am pretty sure that i misconfigured something

3. Caddy version:

My version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

a. System environment:

I have installed caddy with Ubuntu 20.04 (package). The Service is running with systemd

b. Command:

systemctl status caddy

d. My complete Caddy config:

my.domain.tld {
  root * /var/www/my.domain.tld/docs
  file_server
  encode gzip

  log {
    level error
    output file /var/www/my.domain.tld/logs/access.log
  }

  php_fastcgi unix//run/php/php7.4-fpm.appintern.sock

  rewrite /map/admin/uploads/(.*) /uploads/{1}
  rewrite /map/admin/gate/(.*) /gate/{1}

}

You can do it like this:

@uploads path_regexp uploads /map/admin/uploads/(.*)
rewrite @uploads /uploads/{re.uploads.1}

@gate path_regexp gate /map/admin/gate/(.*)
rewrite @gate /gate/{re.gate.1}
1 Like

Hi @francislavoie

thank you, and again you safe my day. Your solution is right, I only have to change the rewrite rule a bit, so the working config looks like:

@uploads path_regexp uploads /map/admin/uploads/(.*)
rewrite @uploads /map/uploads/{re.uploads.1}

@gate path_regexp gate /map/admin/gate/(.*)
rewrite @gate /map/gate/{re.gate.1}
1 Like

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