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

Force default language in url

Started by Muut Archive 11 years ago · 4 replies · 489 views
11 years ago

Hi. I recently started to play with Grav in order to know whether it suitable for my next project.

And I have one question. Is there a way to force default language in url?
For example, I have 2 languages: ru and en. Ru is the default. I want for any given url without a language part to redirect to */ru/*. I know that currently it is available only for home page, using a home_redirect setting.
Currently I ended up with the following setting in
system.yaml*:
--- yaml
home:
aliases:
ru: '/home'

languages:
home_redirect:
include_lang: true
include_route: false
supported:

  • ru
  • en
    TXT
    
    

This results in the correct work of routes /ru/, /ru/{anything}. And / correctly redirects to /ru/. But routes /ru/{anything} and /{anything} produces the the same page, which is not very good for seo. I want /{anything} to redirect to /ru/{anything}. Or at least to answer 404 when someone requests /{anything}. Is it possible in Grav? Or it can be done only using web server rewrite?

11 years ago

Nope. That will redirect only if I request the root resource i.e. /. If I request e.g. /blah it would be processed as is without including the language code

11 years ago

Currently you need to do it with a rewrite. There is an issue on the tracker, that is asking for the other way, i.e. anything that is /ru/{anything] be directed to /{anything} as that is the default language.

It's something I plan on getting to, but as it can be done with rewrites pretty easily, i'm focusing on admin things at the moment.

11 years ago

Ok. Thanks for the answer. I'll keep in mind that this feature will be implemented in the near future. :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1336 9 years ago
Archive · by Muut Archive, 9 years ago
2 925 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago