YII2 Advanced Frontend And Backend Virtual Host


XAMPP Server:

1. xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
   ServerName frontend.dev
   DocumentRoot "E:/xampp/htdocs/dev2017/yii2tuts/frontend/web"

   <Directory "E:/xampp/htdocs/dev2017/yii2tuts/frontend/web/">
       # use mod_rewrite for pretty URL support
       RewriteEngine on
       # If a directory or a file exists, use the request directly
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       # Otherwise forward the request to index.php
       RewriteRule . index.php

       # use index.php as index file
       DirectoryIndex index.php

       # ...other settings...
   </Directory>
</VirtualHost>

<VirtualHost *:80>
   ServerName backend.dev
   DocumentRoot "E:/xampp/htdocs/dev2017/yii2tuts/backend/web"

   <Directory "E:/xampp/htdocs/dev2017/yii2tuts/backend/web/">
       # use mod_rewrite for pretty URL support
       RewriteEngine on
       # If a directory or a file exists, use the request directly
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       # Otherwise forward the request to index.php
       RewriteRule . index.php

       # use index.php as index file
       DirectoryIndex index.php

       # ...other settings...
   </Directory>
</VirtualHost>

System hosts path:

C:\Windows\System32\drivers\etc\hosts

127.0.0.1       localhost
127.0.0.1       localhost

127.0.0.1       frontend.dev
127.0.0.1       backend.dev

Add .htaccess file in side project folder.

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

project Structure





Restart Your XAMPP Server.

Type URL frontend 
http://frontend.dev

Type URL frontend 
http://backend.dev

Demo






Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment