pretty url not working

I change from version 1.1 to 2 and i can not get pretty url working, here are my questions (for some of the questions i know the answer but i want to compare my actual understranding)

Im using Yii2 advance.

1- For enabling preatty url what its the file (path/file) that i have to modify, its frontend/config/main.php or frontend/config/main-local.php

2- One of my actuals url in my localhost server is localhost/webs/project/projectinyii/frontend/web/index.php?r=site%2Fcontact :

to acces this same page but with preatty url witch will be the new url (i know this one i just want to be shure).

Thanks in advance!!!!

Inside common/config/main.php configure urlManager like this inside the components section:




'urlManager' => [

    'class' => 'yii\web\UrlManager',

    'enablePrettyUrl' => true,

    'showScriptName' => false,

],



So your components array may look like this:




'components' => [

    // other config

    'urlManager' => [

        'class' => 'yii\web\UrlManager',

        'enablePrettyUrl' => true,

        'showScriptName' => false,

    ],

    // other config



If you want to hide index.php from your url you need to use .htaccess ( in case you are using apache )

Create .htaccess file inside frontened/web and backend/web folders and put this code in it:




RewriteEngine on


# If a directory or a file exists, use the request directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward the request to index.php

RewriteRule . index.php



If you are using Nginx I do not know what you have to do, read this it may help.

1 Like

Thakns!!!!! , I post those questions because i have the following problem:

With the " ‘enablePrettyUrl’ => false," on my home page when i click on the contact menu it take me to this url

localhost/webs/projects/inYii/frontend/web/index.php?r=site%2Fcontact

and that its fine , work perfect, but when i set " ‘enablePrettyUrl’ => true," it take me to this url

localhost/webs/projects/inYii/frontend/web/site/contact but it tell me this

Not Found

The requested URL /webs/pixWeb/pixWeb/frontend/web/site/contact was not found on this server.

Im using Yii advance project and apache in a windows enviroment

Any clues…!! thakns in advance!!

I found what was my problem,

The rewrite module of my apache was not enable, !!! just enable that module and TADA!!!! work!!!! thats!!

your way works fine for me too