1

I want use pretty url in yii2

in web directory .htaccess file:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

In config/web.php:

'urlManager' => [
     'class' => 'yii\web\UrlManager',
     'baseUrl' => '/',
     'enablePrettyUrl' => false,
     'showScriptName' => false,
     'enableStrictParsing' => true,
     'rules' => [
         '/' => 'view/index',
         'about' => 'view/about',
         'contact' => 'site/contact',
         'login' => 'site/login',
         'logout' => 'site/logout',
         'captcha' => 'site/captcha',
         'signup' => 'site/signup',
     ],
 ],

when url is localhost page loads view/index like urlmanager but on localhost/about or localhost/about.php or any other url to load view/about, it loads view/index again.

ankitr
  • 5,992
  • 7
  • 47
  • 66
javad
  • 11
  • 1
  • Do you have two controllers? ViewController with actions for index and about and SiteController with actions contact, login, logout, captcha, signup? The rules will be used only if enablePrettyUrl is set to true - update your post if you have changed this already. – robsch Sep 26 '15 at 06:49

2 Answers2

0

Perhaps you should change from

enablePrettyUrl=>false

to

enablePrettyUrl=>true

ankitr
  • 5,992
  • 7
  • 47
  • 66
Nate
  • 2,720
  • 2
  • 16
  • 17
0

change with

'urlManager' => [
        'class'=>'yii\web\UrlManager', 
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        //'enableStrictParsing' => false,
        'rules' => [
        //.....
        ],
    ],
jack
  • 663
  • 1
  • 8
  • 11