How To Enable mod_rewrite For Apache in Rocky Linux 8 / Alma Linux 8

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. On Debian and Ubuntu, it is effortless to enable mod_rewrite, which is an Apache utility to rewrite addresses in our applications. However, in the case of Rocky Linux 8 / Alma Linux 8 the issue is not the same. So, you will learn how to enable mod_rewrite for Apache in Rocky Linux 8 / Alma Linux 8.

The rewrite module

The rewrite module is a default module in Apache. This module allows you to generate dynamic URLs that replace the ones generated by your website or application. One of the main advantages is that these alternative addresses do not affect the performance, but above all they are more readable for everyone.

By default, it is present in all Apache builds, but we have to enable it so that we can use it on our site.

In the case of Ubuntu and Debian, the process is reduced to a single command so that applications can make use of it.

Today, you will learn how to do this in Rocky Linux 8 / Alma Linux 8.

Let’s get started.

How to enable mod_rewrite for Apache in Rocky Linux 8 / Alma Linux 8

The first thing we need to do, after installing Apache on Rocky Linux 8, is to make sure that mod_rewrite is not enabled.

To achieve this, simply run the following command

httpd -M | grep rewrite

If you get output that looks like this

rewrite_module (shared)

Then the module is enabled and there is nothing more to do.

Otherwise, we can continue.

If it is not enabled, then we have to edit the Apache configuration file.

sudo vi /etc/httpd/conf/httpd.conf

And look for the following line

#LoadModule rewrite_module modules/mod_rewrite.so

And remove # from the beginning of the line. Then it will look like this:

LoadModule rewrite_module modules/mod_rewrite.so
1.- Enable the mod_rewrite for Apache in Rocky Linux 8 / Alma Linux8
1.- Enable the mod_rewrite for Apache in Rocky Linux 8 / Alma Linux8

In case you can’t find this line, just add it

Save the changes and close the editor.

The next step is to enable the module in the configurationfile of each new site. This is useful because with .htaccess we will be able to redirect URLs without modifying the general Apache configuration.

All you have to do is inside the directive <Directory /var/www/html> add this

AllowOverride All

If the AllowOverride directive already exists, then you have to set it to All as in the example.

To apply the changes, close the editor and restart Apache.

sudo systemctl restart httpd

And you are done.

Conclusion

Hopefully, this short but interesting post will help you to get better with Apache web server on a system like Rocky Linux 8. Now you know how to enable this module in a simple way.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook