Yii2 provides the default URL with frontend/web and backend/web. In actual web applications, URL displays like this are not attractive, so in this case, we need to remove or conceal the frontend/ web from the URL.
There are several ways to do this, in the example below we will do it in a way:
- Using a virtual host
- Modify Yii2
1. Virtual host apache
To hide the frontend /web and backend/web on apache you can do this by creating a virtual host. Open the apache configuration file “…apacheconfextrahttpd-vhosts.conf” with notepad. Add it to the last line
ServerName frontend.bardimin
#sesuaikan with yii installation directories created
DocumentRoot "C:/xampp/htdocs/yii2-test/frontend/web/"
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
DirectoryIndex index.php
ServerName backend.bardimin
#sesuaikan with yii installation directories created
DocumentRoot "C:/xampp/htdocs/yii2-test/backend/web/"
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
DirectoryIndex index.php
Then edit the hosts file on “C:WindowsSystem32driversetchosts” with notepad and add it to the last line
#sesuaikan with ServerName as above
127.0.0.1 frontend.bardimin
127.0.0.1 backend.bardimin
To access the results from the browser type the URL address as follows:
Frontend: http://frontend.bardimin/ –
backend: http://backend.bardimin/
2. Modify Yii2
The second way, namely by creating directory copies of “assets” and “css” as well as“index.php” files that exist in the “frontend/web” directory to the Yii installation root directory.

Then open the index.php file and copy the following code.
run();
To access the results from the browser type the URL address “http://localhost/” in the Yii installation directory, for example, “http://localhost/yii-advanced”.
0 Comments