Enable Apache mod_rewrite Module

How to enable Apache mod_rewrite

The Apache web server is a very popular web server among various Linux distributions. 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. If you’re not sure 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.

 

 

Once installed, start Apache using systemctl:

 

 

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

 

 

You should see the following output if Apache is running.

 

 

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:

 

 

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

 

 

If the module is not listed in the output you’ll need to enable it. Generally this can be accomplished 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.

 

 

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

 

 

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

 

 

 

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

 

 

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


Share:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.