Monthly Archives: February 2016

htaccess in yii2 basic app


.htaccess is a configuration file, by which apache can handle redirects which are not written in php code. So for e.g.  if you want to redirect your users to specific page when 404 error comes, you can do it with a line of code in .htaccess file.

In Yii2 basic app, if you have chose pretty url enabled(and of course you want to make pretty url), than you need to add two htaccess files. Which are mentioned below with path information.

1. BasicApp ( root ) > .htaccess

2. BasicApp ( root ) > web > .htaccess

That’s it.

If you are going to enable pretty url, than you need to add below code snippet in web.php

All the best with .htaccess

And add

$baseUrl = str_replace('/web', '', (new \yii\web\Request)->getBaseUrl());

to head of web.php

and add

'components' => [
    'request' => [
        // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
        'cookieValidationKey' => 'dMDKbOHxH3zzTpLq_6RAqVhn8R6zWY9F',
        'baseUrl' => $baseUrl,

Copy from:

Leave a comment

Posted by on February 17, 2016 in PHP, Yii