How to enable Apache mod_rewrite

What is Apache mod_rewrite?

Apache mod_rewrite provides a way to modify incoming URL requests, dynamically, based on regular expression rules. This allows you to map arbitrary URLs onto your internal URL structure in any way you like, you can take a look at the Apache’s website for more details at the following page:

Apache mod_rewrite and WordPress

You may wonder why do I have to learn about Apache mod_rewrite if I’m using WordPress? that really is a good question, and the answer comes when you start playing around with the WordPress permalinks, you must know that the changes you make there won’t take any effect if the Apache mod_rewrite is not enabled on your system.

Enabling Apache mod_rewrite

Depending on your Linux distro, you’ll find that the Apache mod_rewrite could comes enabled (CentOS 7) or disabled (Linux Mint) by default, in this article we’re going to learn how to verify the status of the Apache mod_rewrite on Linux CentOS 7.

How to verify that Apache mod_rewrite is enabled

CentOS 7 and other Red Hat based distros have an specific file where all the Apache’s modules are listed, to make sure that “mod_rewrite” is enabled on your Apache web server, you must take a look at the file called 00-base.conf located at the following path.

Apache modules list file path

If you are using WinSCP then this step is just a piece of cake, on your Red Hat based OS (in our case CentOS 7) browse the folders until you reach the file, open it by double clicking over it, hit the binocular icon enter the keyword and voila!


checking mod_rewrite – enabled OK

Apache mod_rewrite enabled OK

If you find the hash symbol “#” before a line, it means that this particular module is “commented” and therefore is not enabled, remove the “#” to enable the mode and close the file saving the changes, you must reload Apache after that change.

Reload Apache web server

In order to make this change to take effect you must reload Apache using the following CLI command.

systemctl restart httpd.service

Where to go next?

Now that you are absolutely certain that Apache mod_rewrite is activated, you can test it creating a simple URL redirection, take a look at the following article to learn how.