3

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.

Anil Chaudhari
  • 801
  • 14
  • 30
  • Could you please clarify a little? You have your frontend application running under your normal URL (example.com) and you want your subdomain (sale.example.com) to be redirected to the module? So you have two frontend-parts if you want so? If this is the case I think I have your answer... – PLM57 Sep 22 '15 at 07:58
  • Yeah.. Lets say I have two frontend. But I have used same layouts for these frontend and modules... I just want my module `sale` displayed as `sale.example.com` – Anil Chaudhari Sep 23 '15 at 08:05

1 Answers1

0

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>',
        ],
    ],
Ziya Vakhobov
  • 465
  • 4
  • 10