Redirect or rewrite http://site.fr/path/to -> https://site.fr/another/path

1. Output of caddy version:

Version 2.5.2

2. How I run Caddy:

Under docker and listening on :80 and :443

a. System environment:

Docker on debian

b. Command:

docker restart caddy

c. Service/unit/compose file:

version: '3.9'

services:
    caddy:
        image: 'caddy:latest'
        container_name: 'caddy'
        restart: always
        ports:
            - '80:80'
            - '443:443'
        volumes:
            - './Caddyfile:/etc/caddy/Caddyfile'
            - './caddy_config:/config'
            - './caddy_data:/data'
        networks:
            - webgateway

networks:
    webgateway:
        external: true

d. My complete Caddy config:

glpi-test.example.fr {
        file_server
        reverse_proxy glpi
        rewrite /plugins/fusioninventory/* /front/inventory.php
        encode gzip
        tls internal
}

3. The problem I’m having:

The problem I’m having is that I have updated GLPI version to the latest but a lot devices (PDA) are pointing on the older link: http://glpi-test.exampl.fr/plugins/fusioninventory/. Now, I’m able to rewrite this url if this is in https but I can’t redirect the http…

4. Error messages and/or full log output:

I don’t have any error. It just doesn’t work.

Paste logs/commands/output here.
USE THE PREVIEW PANE TO MAKE SURE IT LOOKS NICELY FORMATTED.

5. What I already tried:

I tried something like:

https://glpi-test.example.fr {
        file_server
        reverse_proxy glpi
        encode gzip
        tls internal
}

http://glpi-test.example.fr {
        reverse_proxy glpi
        rewrite /plugins/fusioninventory/* /front/inventory.php
}

Which works but it also enable http access for the site.

Sorry, if I’m not clear, I still have to learn a lot of things.

Thank you for your help !

edit:
BTW, I’m using Caddy only for reverse proxy.

I did this:

https://glpi-test.example.fr {
        reverse_proxy glpi
        rewrite /plugins/fusioninventory/ /front/inventory.php
        encode gzip
        tls internal
}

http://glpi-test.exampl.fr/plugins/fusioninventory/ {
        reverse_proxy glpi
        rewrite /plugins/fusioninventory/ /front/inventory.php
}

And now it works in http only on specific url but i don’t know if this is “clean”. Also, how can I get a valid certificate for https ?

Site blocks like this with a path matcher are deprecated (see your logs for a warning), and will be removed in a future version. Instead, you can configure it like this:

http://glpi-test.example.fr {
	handle /plugins/fusioninventory/ {
		rewrite * /front/inventory.php
		reverse_proxy http://glpi
	}

	handle {
		redir https://{hostport}{uri} 308
	}
}

This will match only that one URL and rewrite + proxy it, and anything else will be redirected to HTTPS, preserving the URL.

Thanks !! I saw the logs and that’s what I was searching when I asked for cleaner method.

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