Setting up for Yii2

Updated on 28 Dec 2018

You can either do this directly in the Apache configuration file, or you can provide a .htaccess file in your yii/web folder. Further information can be found here

Apache Configuration

My configuration differs slightly from the official yii website in that I am taking into consideration the use of an alias where I am having to use RewriteBase.

RewriteEngine on
AddDefaultCharset utf-8

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
# I added the rewrite base because of the use of alias...
RewriteBase /yii1/
RewriteRule ^(.*)\?*$ index.php/$1

Note, if nothing seems to work for the RewriteRule, then you can fall back to the default.

RewriteRule . index.php