Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Redirects don't seem to work with umlauts in the old urls

Solved by Anna View solution

Started by Anna 5 years ago · 4 replies · 594 views
5 years ago

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:

TXT
/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!

5 years ago

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…

5 years ago Solution

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.

5 years ago

@Netzhexe,

Try the following without the trailing /:

TXT
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:

PHP
$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

last edited 10/07/21 by pamtbaau
5 years ago

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. 😂)

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
3 92 3 hours ago
Support · by Anna, 3 days ago
2 94 23 hours ago
Support · by Justin Young, 1 day ago
1 62 1 day ago
Support · by Duc , 1 week ago
2 98 6 days ago
Support · by Colin Hume, 1 week ago
2 91 6 days ago