I have a multilanguage setup with two languages (de/en)
. Users can switch languages using a language switcher and a search input in the menu bar. The language switcher is redirecting the current de
url to the en
current url. www.example.com/de/something
to www.example.com/en/something
The issue: on the search results page www.example.com/en/search?q=teststring
, when switching languages the query string ?q=teststring
gets lost. Instead of redirecting to www.example.com/de/search?q=teststring
it’s redirecting to www.example.com/en/search
.
(Also, the /search
page is actually a hidden page.)
Am I missing something implementing the language switcher?
Thanks for any input!
Does it make sense to keep the search string? After all, a search term “Hamsterkäfig” wouldn’t yield any results in the English variant and vice versa?
1 Like
Hm, you’re right, that makes sense.
I guess I need a route for the /search
page if the language is switched on the results page. Or is there some other trick?
From what you posted above, the language switch redirect seems to be correct? Or what’s wrong with www.example.com/en/search
?
1 Like
There’s actually no www.example.com/search
page the www.example.com/search
page is only to display the search results.
If there’s no search query in the url, the www.example.com/search
page shouldn’t be accessible at all. That means, the only search input field is in the menu bar.
So I guess, I basically need a route for if no search query redirect www.example.com/search to home or something
. Hm.
Then I wouldn’t put the search into the language switcher?
What do you mean exactly? I can’t follow
Do you mean to make an if clause that’s excluding the /search
page from translation?
(Thanks for your input btw!)
Why is there a link to the search page in the navigation if the search page is only there to display the search results?
Yes, you can use an if statement
That’s a misunderstanding i think, there’s no link in the navigation bar just the search input
field which is redirecting to /search?q
on submit.
I’ll figure out a route then.