So I’m working on a relaunch, and the old site uses umlauts in some urls. This seems to break the redirects… Redirects without umlauts work fine. I tried them as-is and also encoded:
/wir-über-uns/ >> /wir-ueber-uns
/wir-%C3%BCber-uns/ >> /wir-ueber-uns
But both give me a Crikey error with “Call to a member function getRoute() on null”. Not sure what the problem is. Possibly a bug? Any ideas are much appreciated!
I found some more forum posts and things on the internet, and this seems to be a general problem with the recognition, the parsing of umlauts in redirect urls. I found a nice idea for a solution: basically put some wildcards in place of the umlauts. However, I tried /wir-(.*)-uns/
which would be enough of a match, but that doesn’t work either…
Aaaaaand i managed to fix it. Although I don’t really understand how or why this works, here you go:
/wir-(.*)/
Still enough of a match, and redirects perfectly.
@Netzhexe,
Try the following without the trailing /
:
redirects:
'/wir-%C3%BCber-uns': '/wir-ueber-uns'
-or-
'/wir-.*ber-uns': '/wir-ueber-uns'
-or-
'/wir-.{6}ber-uns': '/wir-ueber-uns'
Note: Grav uses internally /wir-%C3%BCber-uns
as current url. Note it has not trailing /
.
Btw. I suspect the /wir-(.*)/
, with the trailing /
, doesn’t work. Maybe a typo?
Why? Because the current Url retrieved by Grav (using $uri->uri(false)
) does not contain a trailing slash. The current url returned is /wir-%C3%BCber-uns
That means the regex: preg_replace($pattern, $replace, $source_url)
will fail with the following values:
$pattern = #^\/wir-(.*)\/# <--- with trailing slash (=your pattern transformed into PHP pattern)
$replace = '/wir-ueber-uns'
$source_url = /wir-%C3%BCber-uns <--- without trailing slash
The $pattern does not match $source_url.
See also code lines Pages.php:1069-1087
Hey there
I tried all your suggestions, and they work! They’re neater, I like that. But apparently Grav’s redirection mechanisms are a bit more complex than that. What I wrote was not a typo: /wir-(.*)/
with the trailing slash does redirect perfectly. However it seems that subdirectories cause some hiccoughs as well – I already found a solution though:
does NOT work:
/news/gr.*nspecht-eg >> /blog/gruenspecht-eg
works:
/.*gr%C3%BCnspecht-eg >> /blog/gruenspecht-eg
It may turn out to be different but for now I’d say that slashes in the middle of redirects with umlauts cause trouble.
(I’m redirecting some two hundred urls and having SO much fun. )