Enabling mod_rewrite on Apache

I do my developments on a Digital Ocean droplet running Ubuntu 16.04. After freshly installing Apache server I wanted to have mod_rewrite module enabled in it.

However I wasn’t sure whether it was already enabled by default with the Apache installation. To check that, I ran below command in my SSH shell:

$ apache2ctl -t -D DUMP_MODULES

It showed me all the currently enabled modules for the Apache server.

Instead of above command, I could also use below command to get the list of enabled modules. (This is in fact an alias to the above)

$ apache2ctl -M

In the list I noticed there was no reference to mod_rewrite so it was evident that mod_rewrite was not enabled. So I have to enable it. To do that I ran below command:

$ sudo a2enmod rewrite

Note that you have to execute a2enmod rewrite with sudo, as it requires root permissions. You will have to type type the password of your logged in user account when prompted.

After executing the command, it showed me a message asking me to restart Apache to activate the changes. Below screenshot shows how I executed the command and the message I got:

As indicated, I restarted the Apache service with below command:

$ sudo systemctl restart apachce2.service

Then I checked to see if the server is running properly. It should show that the service is active (running) (look for the green text of the output)

$ systemctl status apache2.service

Instead of above command, you can also run below command to check the Apache server status. (If it says ‘active‘ then the server is running properly.)

$ systemctl is-active apache2.service

Finally I executed below command again to see if it lists the mode_rewrite module:

$ apache2ctl -M

This time I could mod_rewrite is listed in the Apache’s enabled modules.

rewrite_module (shared)


So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *


Do NOT follow this link or you will be banned from the site!