Search This Blog

Wednesday, 4 September 2013

Procedure to configure Apache Virtual Host with URL Redirection in Windows



Step 1) Open hosts file in notepad or text editor and add your host names in that file.
                goto C:\WINDOWS\System32\Drivers\etc\hosts.file

On a separate line enter 127.0.0.1, followed by some space and the name of the virtual host you want to register in DNS.
For example:
                                127.0.0.1              dizzyworld.benefits.com
                                127.0.0.1              dizzyworld.messaging.com  

Add any further virtual hosts, each one on a separate line and pointing to the same IP address (127.0.0.1). Save the hosts file, and close it.

Step 2) Now Open in notepad and edit  httpd.conf file in conf folder of Apache home.
                Goto C:\Program Files\Apache Software Foundation\Apache2.2\conf


And Uncomment the following line in the Virtual hosts Include section
#Virtual hosts
Include conf/extra/httpd-vhosts.conf


Save and close it.

Step 3) Open httpd-vhosts.conf in notepad and add the virtual hosts configurations in that file.
Goto C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\



Open httpd-vhosts.conf file and following lines.

NameVirtualHost dizzyworld.benefits.com:80
<VirtualHost dizzyworld.benefits.com:80>
    ServerAdmin webmaster@dizzyworld.benefits.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/ dizzyworld.benefits.com "
    ServerName dizzyworld.benefits.com
    ServerAlias www. dizzyworld.benefits.com
    ErrorLog "logs/ dizzyworld.benefits.com -error.log"
    CustomLog "logs/ dizzyworld.benefits.com -access.log" common
    RedirectMatch 301 ^/$             /benefits
    Include conf/extra/benefits.conf
<Directory />
  Options FollowSymLinks
  AllowOverride None
  Order deny,allow
  Allow from all
</Directory>
</VirtualHost>

  
<VirtualHost dizzyworld.messaging.com:80>
    ServerAdmin webmaster@ dizzyworld.messaging.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/ dizzyworld.messaging.com
    ServerName dizzyworld.messaging.com
    ErrorLog "logs/ dizzyworld.messaging.com -error.log"
    CustomLog "logs/ dizzyworld.messaging.com -access.log" common
    RedirectMatch 301 ^/$             /messaging
    Include conf/extra/messaging.conf
<Directory />
  Options FollowSymLinks
  AllowOverride None
  Order deny,allow
  Allow from all
</Directory>
</VirtualHost>
benefits.conf















messaging.conf 















Now save and check the syntax of the both httpd.conf and httpd-vhost.conf by using the following commands.

C:\Program Files\Apache Software Foundation\Apache2.2\bin>httpd  -t


















C:\Program Files\Apache Software Foundation\Apache2.2\bin>httpd  -S


















Step 4) Now restart the Apache Webserver using the following command
C:\Program Files\Apache Software Foundation\Apache2.2\bin>httpd  -k restart







Step 5) Access the virtual host names you configured, it should be work now.
Open Browser and type the URL http://dizzyworld.benefits.com/  (it will redirected to benefits application)





http://dizzyworld.messaging.com