How to configure Apache URL Redirection on Rocky Linux 8.6

To Configure Apache URL Redirection On Rocky Linux 8.6

Introduction

Apache HTTP Server is a free and open-source web server that provides web content through the internet. It is referred to as Apache and after development, it fastly became the most popular HTTP client on the web.

Step 1: Check the OS Version by using the below command

[root@linuxhelp~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"

Step 2: Install the Apache Web server package by using the below command

[root@linuxhelp ~]# yum install httpd* -y
Last metadata expiration check: 0:32:52 ago on Tue 28 Jun 2022 06:19:49 AM EDT.
Dependencies resolved.
=======================================================================================================
 Package                Arch        Version                                       Repository      Size
=======================================================================================================
Installing:
 httpd                  x86_64      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream      1.4 M
 httpd-devel            x86_64      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream      223 k
 httpd-filesystem       noarch      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream       40 k
 httpd-manual           noarch      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream      2.4 M
 httpd-tools            x86_64      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream      107 k

Step 3: Enable and Start the Apache service by using the below command

[root@linuxhelp ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

[root@linuxhlep ~]# systemctl start httpd.service 

Step 4: Check the status of Apache web server by using the below command

[root@linuxhelp ]# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-06-28 06:53:19 EDT; 14s ago
     Docs: man:httpd.service(8)

Step 5: Add firewall for port 80 tcp/udp by using the below command

[root@linuxhelp ]# firewall-cmd --add-port=80/tcp --permanent 
[root@linuxhelp ]# firewall-cmd --add-port=80/udp –-permanent

Step 6: Reload the firewall by using the below command

[root@linuxhelp ]# firewall-cmd --reload

Step 7: Disable SELinux by using the below command

[root@linuxhelp linuxhelp]# setenforce 0

Step 8: Create html file in Apache document root directory in .html format by using the below command

[root@linuxhelp linuxhelp]# cd /var/www/html/

[root@linuxhelp html]# vim index.html
<!DOCTYPE html>
<html>
<body>
<h1 data-style="font-size:300%;">Welcome to Configure Apache URL Redirection </h1>
<p data-style="font-size:160%;"> This is Mohamed Musthakeem.A</p>

</body>
</html>

Step 9: Change ownership and give Execute permission for this directory by using the below command

[root@linuxhelp html]# chown -R apache:apache /var/www/html/
[root@linuxhelp html]# chmod -R 775 /var/www/html/

Step 10: Go to the configuration file location and create test.conf file by using the below command.

[root@linuxhelp html]# vim /etc/httpd/conf.d/test.conf
<virtualhost *:80>
servername test.com
Documentroot /var/www/html/
</virtualhost>

Step 11: Restart the Apache service for changes by using the below command

[root@linuxhlep conf.d]# systemctl restart httpd

Step 12: Put the host entry by using the below command

[root@linuxhlep conf.d]#  vim /etc/hosts

Step 13: Restart the apache service for changes

[root@linuxhlep conf.d]# systemctl restart httpd

Step 14: After restarting the service Open your web browser and search test.com as shown in the below image

Step 15: Now go to the virtual host configuration file to make changes and Configure Apache URL redirection by using the below command

[root@linuxhlep conf.d]# vim /etc/httpd/conf.d/test.conf
<virtualhost *:80>
servername test.com
Documentroot /var/www/html/
Redirect / "https://www.test1.com/"
</virtualhost>

Step 16: Edit the host entry and Restart the Apache service by using the below command

[root@linuxhlep conf.d]# systemctl restart httpd

Step 17: Open the web browser and search test1.com as shown in the below image

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Configure Apache URL Redirection on Rocky Linux 8.6. Your feedback is much welcome.

Tag : Apache Linux URL
FAQ
Q
Where are the configuration directories of the Apache webserver in rocky Linux?
A
The configuration file location in rocky linux is /etc/httpd
Q
How will you install the Apache server on Linux Machine?
A
This is the common Apache Interview Question asked in an interview. We can give the following command for Centos: yum install httpd . For Debian: apt-get install apache2.
Q
What is the port of HTTP and HTTPS of Apache?
A
The port of HTTP is 80, and HTTPS is 443 in Apache.
Q
How to check the Apache version?
A
You can use the command httpd -v
Q
What do you mean by Apache Web Server?
A
Apache web server is the HTTP web server that is open source, and it is used for hosting the website.