Casbay Knowledge Base

Search our articles or browse by category below

HOW TO: Enable Apache mod_rewrite

Last updated: September 7, 2022
Estimated reading time: 1 min

The Apache web server is a very popular web server among various Linux distributions. It’s actively maintained by the Apache Software Foundation. This popularity is partly due to its modular design that allows you to customize the web server to fit your needs by enabling or disabling modules. One of those modules is the mod_rewrite module, which we will cover how to enable in this article.

Before we begin, you’ll need to ensure that you’re logged into your server via SSH.

Step 1 – Ensure Apache is installed and running

If you have not installed Apache at this point you may do so now by issuing the following command. If you have already installed Apache you may proceed 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

You should see the following output if Apache is running.

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

Step 2 – Enable mod_rewrite

Most modern-day versions of CentOS such as CentOS 7 have mod_rewrite enabled by default, however, we can verify this using the following command which will list all currently loaded modules:

httpd -M | grep rewrite

If the mod_rewrite module is currently loaded you should see output similar to the following:

rewrite_module (shared)

If the module is not in the output you’ll need to enable it. Generally, you can accomplish this in one of two ways in a CentOS environment. The first method is to add the following line to the 00-base.conf file using your favorite text editor. For this article, we will be using Nano, as you can see below.

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

Once you have utilized either method to enable the module you’ll need to restart Apache:

systemctl restart httpd

After Apache has restarted the mod_rewrite module should be enabled and can be utilized via a .htaccess file.

Now you have learned to enable Apache mod_rewrite. For more guide articles on the topic Manual/ Guide, visit here.

Was this article helpful?
Dislike 0
Previous: What is the MS FrontPage version?
Next: Disable Enhanced Security Configuration for Internet Explorer in Windows Server 2019/2016
Have questions ? Search our documentations.