Anil Chaudhari
Anil Chaudhari

Reputation: 841

How to setup Yii2 module on subdomain correctly?

I have a project on Yii2 advances app. And I have created a module named 'sale' on front end, Where I have extended layouts of frontend. And now I just want to access that module as a subdomain like http://sale.example.com .

I have created subdomain sale.example.com and set it's document root to root folder public_html (sites's root folder).

I have configures my urlManager like 'http://sale.example.com' => 'sale/default/index', according to Yii2 DOC. And it working fine but all my navigation gone wrong. I mean I think app's homeUrl is not pointing to default site url. My entire url system is changed after sub domains like http://sale.example.com/contact, But this is supposed to be http://example.com/contact . Here is a snapshot.

Thanks in Advance.

Upvotes: 3

Views: 1894

Answers (1)

Ziya Vakhobov
Ziya Vakhobov

Reputation: 465

You can do it using UrlManager. Here is example Just replace your_module_name with real name of your module. More on UrlManager you can see here

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'enableStrictParsing' => false,
        'rules' => [
            'sale.example.com/<controller>/<action>' => 'your_module_name/<controller>/<action>',
        ],
    ],

Upvotes: 0

Related Questions