Yii Framework Forum

UrlManager rule doesn't work in new server


(Nicola) #1

Hi,
i’ve a site working in local and remote server. I’m migrating it on a new server and works.
The only thing i can’t get are (standard) rules for pretty url. These rules works perfectly in development and production, but fails in the new server.

'urlManager'=>array(
               'urlFormat'=>'path',
                'rules'=>array(
                           '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                           '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                           '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
                            ),
                    ),

The error i get is in every detail view (actionView, url like /index.php/controllerName/18652), regardless of the controller used. System say:
System couldn't find the required "18652" action
Seems it miss the action and get the id as action

Also the update actions (url like /index.php/controllerName/update/18652) returns a “400 error”

Any suggestion?
Thanks in advance,
Nicola


(Alirz23) #2

check your url rewrite rules for web server

https://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-10030x


(Nicola) #3

Thank you alirz23 but .htaccess works and rewriterule is on.
That should only be needed to suppress the index.php part of the url, isn’t it?
I suppose that the server or Yii is not able to catch the id part of the url rule…but… why???


(Alirz23) #4

I also believe it has to do something with index.php can you manually remove it and try if that works, can you also make the following changes in your urlManager config

'urlManager'=> array(
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'urlFormat'=>'path',
    'rules'=>array(
        //...
    )
);

(Nicola) #5
  'urlManager'=>array(
                            'urlFormat'=>'path',
                            'showScriptName'=>false,
                            'rules'=>array(
//                                    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
//                                    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
//                                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
                            ),
                    ),

Without rules it works, with or without index.php in the url (with modification to htaccess to remove the index.php part)

With rules, doesn’t work!

Thanks!


(Alirz23) #6

I think it could be related to urlFormat try removing that with settings I posted above


(Nicola) #7

enablePrettyUrl is a yii2 property :frowning: