Open Lucidiot opened 2 years ago
Wouldn't you want to use 301 or 302 in that case?
Well if we could get the server to redirect a few URLs, we would, but in many cases such as using GitHub Pages, you just do not have control over the server's responses. Zola already has aliases
and redirect_to
to work around this and use a small webpage to redirect, and redirecting to an external URL instead of an internal one does not seem to make much of a difference.
I made a workaround by copying the built-in internal/alias.html
template over to the site's templates and using a custom variable in [extra]
instead of redirect_to
to avoid getting the base URL appended. So I guess just not adding the site's base URL when the destination URL is already absolute would fix this?
This seems like the code responsible for adding the base URL. Adding a check for :
for an absolute path should be easy enough.
It should be changed upstream of that function, not in there. This function is responsible for making permalinks in the current site.
Ah, sorry. That makes sense. Anyway, I'd be happy to tackle this issue if it gets approved.
Sorry for the very late reply. I think it would be ok to add
Huh, from what I can see in the code is that link parsing in articles is done by the pulldown-cmark
library, and functions in Zola assume that the link they're getting needs to be appended to the base_url
in most cases to work. Is that correct?
In this issue, you only need to handle the redirect on a section so the line you have to change is https://github.com/getzola/zola/blob/next/components/site/src/lib.rs#L1117 Make a check whether the URL is external (there is a function for that in the markdown subcrate which should be extracted to the utils one) and do not generate a permalink if that's the case.
Bug Report
Environment
Zola version: 0.15.3
Expected Behavior
Tell us what should have happened.
When setting
redirect_to
on a section's_index.md
to an external URL, the redirection page should redirect to the external URL.Current Behavior
Tell us what happens instead of the expected behavior. If you are seeing an error, please include the full error message and stack trace. You can get the stacktrace of a panic by adding
RUST_BACKTRACE=1
when running azola
command.The site's base URL gets concatenated to the external URL: with a base URL at
https://foo.com
andredirect_to = "https://bar.com/something"
, the user gets redirected tohttps://foo.com/https://bar.com/something
.Step to reproduce
Please provide the steps to reproduce the issue. If the issue is hard to reproduce, please provide a sample repository or sample that triggers the bug.
Set the site's base URL to
https://foo.com
Create an
_index.md
anywhere in a site's content, and set a redirection:Generate the site.
Open the section that you created.
You will get redirected to
https://foo.com/https://bar.com/something
.