Multiple path redirects, only one works

Caddy v2.2.1, on Linux Debian 9 (Stretch), using Caddyfile config

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
www.metalchain.ca {
	redir https://metalchain.ca{uri}
}

metalchain.ca {
	redir /solarion https://youtube.com/watch?v=v8vR9Di_ITs
	redir /twitch https://twitch.tv/MetalChain_
	redir /twitter https://twitter.com/_MetalChain
	redir /donate https://ko-fi.com/MetalChain
	redir /home https://metalchain.ca
}

# Set this path to your site's directory.
root * /var/www/html

# Enable the static file server.
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

Now, as you can see from my Caddyfile I’m attempting to do multiple redirects, specified by path. The first one in the order works (/solarion), yet the others merely sit on a white page with the same URL in the browser bar.

I’ve tried using redirects by specifying a new site for each redirect (forgive my poor terminology), with the same result.
i.e:

metalchain.ca/solarion {
    redir https://youtube.com/watch?v=v8vR9Di_ITs
}

I’ve also tried having an index page in said paths with a meta redirect, but this causes some side-effects with regards to how APIs interpret the redirect (i.e. not at all)

I’m sure there’s some very obvious quirk that I’m missing, but I’ve yet to find the cause/workaround to my issue.

(Also, obligatory thank you, my experience with other webservers have been grueling, and as a beginner, this is a dream come true lol)

EDIT: I’ve also just now noticed that this breaks my main index page lol

I just tried accessing https://metalchain.ca/twitch and I have good news for you, it works. :man_shrugging:

Try with curl -v ... – are you sure it’s not a browser cache issue or something?

Edit: Btw, these directives are orphaned:

# Set this path to your site's directory.
root * /var/www/html

# Enable the static file server.
file_server

Make sure to put them in a site block. Caddyfile Concepts — Caddy Documentation

2 Likes

You’re very right. Oddly enough, after I had cleared my cache, the main site still wasn’t working, but after putting those directives where they should be, that solved that issue as well.

Thank you for your expertise, as basic as it may have seemed lol

2 Likes

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