5

Suppose my application path is:-

http://www.example.com/index.php?r=dashboard/event/view

I make a new controller on which I want to change the URL to pretty URL.

Default URL for the new controller

http://www.example.com/index.php?r=newcontroller/view?id=23&name=urlpretty

I want to make above URL to pretty URL such as

http://www.example.com/23/sampleprettyurl

But I do not want to change the complete application URL path to pretty URL. My other controller path/URL should work normally.

Thanks in advance

pawansgi92
  • 935
  • 10
  • 24
  • 3
    never done that but one thing pops in mind to have 2 `UrlManager` defined as `UrlManager` and `UrlManagerPretty` which will have only one difference in the configurations i.e `'enablePrettyUrl' => true,` for the `urlManagerPretty` and `'enablePrettyUrl' => false,` for the `UrlManager` then you need to create all your urls that need to be pretty using `Yii::$app->urlManagerPretty->createUrl()` and all the rest with `Yii::$app->urlManager->createUrl()` – Reborn Jan 29 '19 at 10:51
  • How we can define them ...currently I do not define any ... – pawansgi92 Jan 29 '19 at 11:38
  • What do you mean by "My other controller path/URL should work normally"? If you set up pretty urls, the long and ugly urls should be still working. – t6nnp6nn Mar 20 '19 at 20:15
  • `?r=newcontroller/view?id=23&name=urlpretty` u cant use this way double question to pass params – SiZE Mar 23 '19 at 06:19

2 Answers2

0

I don't think is doable, controller name must be in the URL, get what you need to configure the module name, then the urlManager:

    'urlManager'   => [
      'enablePrettyUrl'     => true,
      'showScriptName'      => false,
      'enableStrictParsing' => false,
      'rules'               => [
              'newcontroller/<id>/<name>'   => 'moduleAlias/newcontroller',
       ],
     ],

Then in the action you can get the value by Yii::$app->request->get('id');

Marvix
  • 131
  • 2
  • 12
-1

in config web.php

component => [
/* pretty url */
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
/* ./pretty url */
]

and .htaccess on /web

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Arbahud Rio Daroyni
  • 1,859
  • 2
  • 6
  • 7