How to setup a virtual host when frontend and backend are on same level in root folder

827 views Asked by At

I have following directory structure

MyWebsite
    Frontend
    Backend

Where MyWebsite is a root folder. Frontend is the files for the website whereas Backend is for the admin panel.

I want to setup a virtual host in such a way that When user types http://www.mywebsite.com, it will be pointed to Frontend folder And when user types http://www.mywebsite.com/backend, it will be pointed to Backend Folder

As Frontend and Backend folder is in same level under root diretory, i can only make work one at a time (either Front end or Backend) but not both. How can it be done?

Here is my Virtual host so far

<VirtualHost *:80>
    DocumentRoot "D:/server/www/MyWebsite/Frontend"
    ServerName www.mywebsite.com
    ServerAlias mywebsite.com
</VirtualHost>

Thanks

1

There are 1 answers

0
WatsMyName On

Nevermind, I used htaccess to handle the situation and leaving the virtual host setting as it is. Below is the code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$ [NC]
RewriteCond %{REQUEST_URI} !^/Frontend/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Frontend/$1
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$ [NC]
RewriteRule ^(/)?$ Frontend/ [L]