Pretty urls in yii2


  1. Make Sure mod_rewrite enable
  2. Create .htaccess file in /backend/web/.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine on

    # If a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise forward it to index.php
    RewriteRule . index.php
    </IfModule>

  3. Go to your backend/config/main.php add urlManager in components

     ‘urlManager’ => [
    ‘class’ => ‘yii\web\UrlManager’,
    ‘enablePrettyUrl’ => true,
    ‘showScriptName’ => false
    ],

 

 

Advertisements