Need help? Chat now!

Hostwinds Tutorials

Search results for:


Table of Contents


How to enable Apache mod_rewrite
Step 1 – Ensure Apache is installed and running.
Step 2 – Enable mod_rewrite

Enable Apache mod_rewrite Module

Tags: Apache 

How to enable Apache mod_rewrite
Step 1 – Ensure Apache is installed and running.
Step 2 – Enable mod_rewrite

How to enable Apache mod_rewrite

The Apache web server is a prevalent web server among various Linux distributions. This popularity is partly due to its modular design that allows you to customize the webserver 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. If you're unsure how to access your server using SSH, please refer to our guide, which covers this topic in more detail: Connecting to 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 listed in the output, you'll need to enable it. Generally, this can be accomplished 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 utilized via a .htaccess file.

Written by Michael Brower  /  June 22, 2017