Wesbytes Knowledge Base

Search our articles or browse by category below

How to Enable Apache mod_rewrite

Last modified: July 2, 2022
You are here:
Estimated reading time: 1 min

Various of the Linux distributions use the Apache web server, which is a very well-liked web server. The Apache Software Foundation actively maintains it. This popularity is largely attributable to the web server’s modular nature, which enables you to tailor it to your needs by activating or deleting modules. One of these is the mod rewrite module, which we shall discuss in this article’s section on how to enable.

You must make sure that you are SSH-logged into your server before we can start.

Step 1 – Ensure Apache is installed and running

You can install Apache right now if you haven’t already by typing the following command. If Apache is already installed, move on to the next step.

yum install httpd -y

Once installed, start Apache using systemctl:

systemctl start httpd

You can check to make sure that Apache is running using the following command:

systemctl status httpd

The output could be displayed if Apache is running:

systemd[1]: Starting The Apache HTTP Server…systemd[1]: Started The Apache HTTP Server.

Step 2 – Enable mod_rewrite

Mod rewrite is typically enabled by default in most recent versions of CentOS, such as CentOS 7, but we can confirm this by running the command listed below, which will display all currently loaded modules:

httpd -M | grep rewrite

You should see output resembling the following if the mod_rewrite module is currently loaded:

rewrite_module (shared)

You must enable the module if it is not listed in the output. In a CentOS system, you can typically achieve this in one of two methods. The first technique entails using your preferred text editor to add the following line to the 00-base.conf file. As you can see in the example below, we’ll be utilising Nano.

nano
/etc/httpd/conf.modules.d/00-base.conf

Once the file is open, add or uncomment the following line:

LoadModule rewrite_module
modules/mod_rewrite.so

The second method is to add or uncomment the same line used above to the httpd.conf file directly:

nano /etc/httpd/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so

You must restart Apache after using either approach to enable the module:

systemctl restart httpd

The mod rewrite module should be activated once Apache has restarted and can be used through a.htaccess file.

Was this article helpful?
Dislike 0
Views: 20