Yii2 Default htaccess file

Yii2 is a opensource, object oriented component-based MVC PHP advance web application framework which is a good choice to develop web applications and web sites. In most cases users will get errors because of Yii2 Default htaccess file . From this post you can see how to add Yii2 Default htaccess file to your project folder.

Yii2 Default htaccess file

In Yii you have to put 2 htaccess files.one is for root folder and other one is for web folder. Check below steps how to create Yii2 Default htaccess file.

Step 1

Create a htaccess file in root and add below code


    Options +FollowSymlinks
    RewriteEngine On

 

    RewriteCond %{REQUEST_URI} ^/.*
    RewriteRule ^(.*)$ web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/web/
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ web/index.php
 

Step 2

create a htacess file in {root}/web/ and add below code

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Step 2

update file in {root}/config/web.php as below

'request' => [
    'baseUrl' => '',
],
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        '' => 'site/index',
        ''=>'site/',
    ],
],

And that’s it. you have successfully added Default htaccess file. to your project folder. Check with the urls and pleases give a comment below.

More Helpful Information

Leave a Reply

Your email address will not be published. Required fields are marked *

78 + = 83