[yii2] Easy way to hide frontend/web and backend/web

20 May 2021

Home » Blogs » Technology » [yii2] Easy way to hide frontend/web and backend/web

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:

  1. Using a
  2. Modify Yii2

1. Virtual host apache

To hide the frontend /web and backend/web on you can do this by creating a virtual host. Open the 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 type the URL address as follows:

TOP TUTORIALS:  How to create a virtual USB Flash drive in Windows 10

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.

copy to rooot

Then open the index.php file and copy the following code.

run();

To access the results from the type the URL address “http://localhost/” in the Yii installation directory, for example, “http://localhost/yii-advanced”.

0 Comments