Video tutorial: customize the url in Yii Framework version 2.0

Hi guys! In this tutorial I will explain to you how you can easily customize the url of your Yii Framework 2.0 project. I have also created a video were you can see how it works.

So, first of all, open your config/web.php file and add this code:

'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false',
'rules' => [
'<alias:contact|index|about|login>' => 'site/',
],
],

This code works with contact, index, about and login page. You can add new pages if you want.

Then, add this code:

RewriteEngine on

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

RewriteRule . index.php

in your web/htaccess file.

Video tutorial:

If you want to remove the web/ parameter from your url, upload your project on your server on route folder and rename the web/ folder to public_html.









Leave a Comment