Two problems with rules in pretty urls

I used rules from UrlManager like this:




      'home'         =>   'site/index',

      '<alias:\w+'   =>   'site<alias>', 



And it works I can access my_domain.com/home my_domain.com/contact etc.

Without the first rule I cannot access my_domain.com/home, I would like to have one generic rule not two…so I can resolve the next problem.

After I set up those 2 rules…I installed and configured this language picker http://www.yiiframework.com/extension/yii2-language-picker/

Now I have two flag-links with

my_domain.com/home?language-picker-language=ro-RO

my_domain.com/contact?language-picker-language=en-GB

Well I’m a beginner and I don’t know how to create these rules so I can have

my_domain.com/ro/home

my_domain.com/en/home

You will most likely have to extend url manager to be able to use the urls like you are wanting. You will end up having to make a bunch of rules which will slow your site down if you don’t do something globally like extending url manager. There are a few extensions that you can use here is one but there are more if you search github

https://github.com/c...yii2-localeurls

here is an old forum post too

http://www.yiiframew…site-url-rules/

yii2 url routing guide

http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html

Ok, I’m thinking to use this extension, but I don’t understand a thing… it creates urls(the same way like in the routing guide) like this




     $url = Url::to(['demo/action']);



And I do not know WHERE to create this rules. Would the creation is made in the controller?

You would set the rules in your main config file under components. You would also set the rules like you normally would.

perhaps the guides are not very clear, but you confusing it with something which is related to routing but has different purpose




// imagine you have defined a set of routes

'home'         =>   'site/index',

'<alias:\w+'   =>   'site<alias>', 

you might wanna generate links to these routes to go from one page to another page

in your case lets say you wanna put a link on a page which takes you to site/index action or home route you can use Url::to


// this will generate a link to your homepage

<a href="<?= Url::to(['site/index']) ?>Go to homepage</a>

Ok I suspend the problem for a few months. But now I’ll try to fix it.

Some corrections to my first post




 'home'   =>   'site/index',

 '<alias:\w+>'   =>   'site/<alias>', 



I used https://github.com/codemix/yii2-localeurls

Now I have




     '<alias:\w+(-\w+)*>'   =>   'site/<alias>',



And it works, my default language in my config is ro…and I want that my app to ignore THE DEFAULT LANGUAGE OF THE BROWSER… or any cookies/sessions related to language…so that de default language will be always ro.

LE:

For sessions/cookies I found this solutions




    'enableLanguagePersistence' => false,

    'languageSessionKey'        => false,

    'languageCookieDuration'    => false,