• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Redirect a website using Virtual Host on Ubuntu 21.04

  • 00:37 lsb_release -a
  • 00:54 sudo -s
  • 01:01 cd ~
  • 01:14 apt install apache2
  • 01:30 vi /etc/apache2/sites-available/linuxhelp1.com.conf
  • 03:08 mkdir /var/www/html/linuxhelp1
  • 03:31 vi /var/www/html/linuxhelp1/index.html
  • 05:30 chown -R www-data. /var/www/html/linuxhelp1
  • 06:22 vi /etc/hosts
  • 07:00 cd /etc/apache2/sites-available/
  • 07:18 a2ensite linuxhelp1.com.conf
  • 07:37 systemctl reload apache2
  • 08:22 vi linuxhelp1.com.conf
  • 09:22 systemctl reload apache2
{{postValue.id}}

Method to Redirect a website using Virtual Host on Ubuntu 21.04

Introduction:

In the web server, URL redirect is a technique of pointing one domain or address to another domain or address. It is also an open-source platform that has numerous powerful features and is also regarded as the most prominent web server.

Installation Procedure :

Steps 1: Verifying the OS versionby using following command

linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Steps 2: Changing as Root user by using following command

linuxhelp@linuxhelp:~$ sudo -s
[sudo] password for linuxhelp: 

Steps 3 :Changing the Home Directory to root

root@linuxhelp:/home/linuxhelp# cd ~

Steps 4: Installing apache web server

root@linuxhelp:~# apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
  apache2
0 upgraded, 1 newly installed, 0 to remove and 262 not upgraded.
Need to get 95.9 kB of archives.
After this operation, 543 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 apache2 amd64 2.4.46-4ubuntu1.3 [95.9 kB]
Fetched 95.9 kB in 0s (580 kB/s)   
Selecting previously unselected package apache2.
(Reading database ... 149036 files and directories currently installed.)
Preparing to unpack .../apache2_2.4.46-4ubuntu1.3_amd64.deb ...
Unpacking apache2 (2.4.46-4ubuntu1.3) ...
Setting up apache2 (2.4.46-4ubuntu1.3) ...
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.se
rvice.
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for ufw (0.36-7.1) ...

Steps 5 :Configuring the virtual host for linuxhelp1.com

root@linuxhelp:~# vi /etc/apache2/sites-available/linuxhelp1.com.conf



<VirtualHost *:80>

ServerName www.linuxhelp1.com
DocumentRoot /var/www/html/linuxhelp1

</VirtualHost>

Steps 6: Making document Root directory as linuxhelp1

root@linuxhelp:~# mkdir /var/www/html/linuxhelp1

Steps 7: Making the index.html file for linuxhelp1.com

root@linuxhelp:~# vi /var/www/html/linuxhelp1/index.html

<!DOCTYPE html>

<html>

<body>

<h1>Welcome to linuxhelp</h1>


</body>
</html>

Steps 8: Giving Ownership for DocumentRoot directory

root@linuxhelp:~# chown -R www-data. /var/www/html/linuxhelp1

Steps 9: Editing Host Entry for linuxhelp1.com

root@linuxhelp:~# vi /etc/hosts

Steps 10: Changing to the sites-available directory

root@linuxhelp:~# cd /etc/apache2/sites-available/

Steps 11: Enabling the site by using following command

root@linuxhelp:/etc/apache2/sites-available# a2ensite linuxhelp1.com.conf 
Enabling site linuxhelp1.com.
To activate the new configuration, you need to run:
systemctl reload apache2

Steps 12: Reloading the service by using following command

root@linuxhelp:/etc/apache2/sites-available# systemctl reload apache2

Steps 13: Ping the domain in browser\

Snap 1

Steps 14: Reconfigure the virtual host for linuxhelp1.com

root@linuxhelp:/etc/apache2/sites-available# vi linuxhelp1.com.conf 



<VirtualHost *:80>

ServerName www.linuxhelp1.com
 Redirect / https://www.google.com
DocumentRoot /var/www/html/linuxhelp1

</VirtualHost>

Steps 15: Reloading the service by using following command

root@linuxhelp:/etc/apache2/sites-available# systemctl reload apache2

Steps 16: Refreshing the domain in browser again

Snap 2

By this redirecting a website using virtual host comes to end

Tags:
isaac
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is HTTP redirect?

A

The HTTP redirect has a potential method of forwarding visitors and search engines directly from one URL to another.
An effective way of solving the issues in URL and is mainly used while moving content.

Q

What is Hypertext Transfer Protocol?

A

The Hypertext Transfer Protocol that occurs in the Internet protocol suite as an application layer. It is mainly used to transmit and fetch resources and is designed in a form to communicate efficiently with web browsers and web servers.

Q

How many types of redirects are present in apache?

A

There are seven types of redirects, which are from 301 to 307.

Q

Difference between HTTP and HTTPS

A

HTTP is comparatively faster than HTTPS since it consists of the SSL protocol that makes the HTTP page load slower. The HTTP data are not encrypted which makes it appears less secure.

Q

What is an SSL in web server ?

A

It is an acronym for Secure Sockets Layer and it is mainly designed to ensure secure channeling between machines.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Lucas ?
Various options in Top command

Am using Top command only to view the load average, what are the various options in Top command..??

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.