Clean URL for Yii 2.0

How do I manage/configure clean url for yii 2.0 version?

first add following code in your config file ( web.php in basic)

'urlManager' => [

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

	    'baseUrl' => '/example/web/',

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => [




than create .htaccess file in web folder and add following code…

# "-Indexes" will have Apache block users from browsing folders without a default document

# Usually you should leave this activated, because you shouldn't allow everybody to surf through

# every folder on your server (which includes rather private places like CMS system folders).

<IfModule mod_autoindex.c>

  Options -Indexes




# Block access to "hidden" directories whose names begin with a period. This

# includes directories used by version control systems such as Subversion or Git.

<IfModule mod_rewrite.c>

  RewriteCond %{SCRIPT_FILENAME} -d

  RewriteCond %{SCRIPT_FILENAME} -f

  RewriteRule "(^|/)\." - [F]




# Block access to backup and source files

# This files may be left by some text/html editors and

# pose a great security danger, when someone can access them

<FilesMatch "(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">

  Order allow,deny

  Deny from all

  Satisfy All



# Increase cookie security

<IfModule php5_module>

  php_value session.cookie_httponly true



# Settings to hide index.php and ensure pretty urls

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

by this at final your clean url like

how do we same thing in advance template

If you don’t want to specifically set a rule for each route, then you can add the below:

'enableStrictParsing' => false,


'urlManager' => [

	'enablePrettyUrl' => true,

	'showScriptName' => false,

	'enableStrictParsing' => false,

	'rules' => [