How to Activate mod_rewrite Apache Webserver Module in Linux Ubuntu 19.10 Operating System

Posted on

This article has a specific content for explaining about how to activate ‘mod_rewrite’ in Apache Webserver. One of the actual function having this module is to be able to recognize the ‘RewriteEngine’ line configuration in ‘.htaccess’ file. It is very important in order to modify the URL address of a web-based application running in Apache Webserver. Moreover, the behavior for the URL modification is actually exist in that file of ‘.htaccess’. So, the following is the actual content of the .htaccess for an example :

# BEGIN WordPress
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

The above is an example of the ‘.htaccess’ file for a WordPress-based web application. So, in order to be able to process each of the line exist in that content, there must be a rewrite module in the Apache Webserver and it is active. In order to activate the rewrite module in the Apache Webserver, the following is the step to achieve it :

1. Check that the rewrite module is available. Normally, it exist in ‘/etc/apache2/mods-available’ in the case of Linux Ubuntu distribution specifically in this context, Linux Ubuntu 19.10. The following is the content of the directory :

root@hostname:/etc/apache2/mods-available# ls
access_compat.load  authnz_fcgi.load      cache_socache.load  dir.load           info.conf                 mime_magic.load      proxy_express.load   remoteip.load          socache_shmcb.load
actions.conf        authnz_ldap.load      cern_meta.load      dump_io.load       info.load                 mpm_event.conf       proxy_fcgi.load      reqtimeout.conf        speling.load
actions.load        authz_core.load       cgid.conf           echo.load          lbmethod_bybusyness.load  mpm_event.load       proxy_fdpass.load    reqtimeout.load        ssl.conf
alias.conf          authz_dbd.load        cgid.load           env.load           lbmethod_byrequests.load  mpm_prefork.conf     proxy_ftp.conf       request.load           ssl.load
alias.load          authz_dbm.load        cgi.load            expires.load       lbmethod_bytraffic.load   mpm_prefork.load     proxy_ftp.load       rewrite.load           status.conf
allowmethods.load   authz_groupfile.load  charset_lite.load   ext_filter.load    lbmethod_heartbeat.load   mpm_worker.conf      proxy_hcheck.load    sed.load               status.load
asis.load           authz_host.load       data.load           file_cache.load    ldap.conf                 mpm_worker.load      proxy_html.conf      session_cookie.load    substitute.load
auth_basic.load     authz_owner.load      dav_fs.conf         filter.load        ldap.load                 negotiation.conf     proxy_html.load      session_crypto.load    suexec.load
auth_digest.load    authz_user.load       dav_fs.load         headers.load       log_debug.load            negotiation.load     proxy_http2.load     session_dbd.load       unique_id.load
auth_form.load      autoindex.conf        dav.load            heartbeat.load     log_forensic.load         php7.3.conf          proxy_http.load      session.load           userdir.conf
authn_anon.load     autoindex.load        dav_lock.load       heartmonitor.load  lua.load                  php7.3.load          proxy.load           setenvif.conf          userdir.load
authn_core.load     brotli.load           dbd.load            http2.conf         macro.load                proxy_ajp.load       proxy_scgi.load      setenvif.load          usertrack.load
authn_dbd.load      buffer.load           deflate.conf        http2.load         md.load                   proxy_balancer.conf  proxy_uwsgi.load     slotmem_plain.load     vhost_alias.load
authn_dbm.load      cache_disk.conf       deflate.load        ident.load         mime.conf                 proxy_balancer.load  proxy_wstunnel.load  slotmem_shm.load       xml2enc.load
authn_file.load     cache_disk.load       dialup.load         imagemap.load      mime.load                 proxy.conf           ratelimit.load       socache_dbm.load
authn_socache.load  cache.load            dir.conf            include.load       mime_magic.conf           proxy_connect.load   reflector.load       socache_memcache.load
a2enmod rewrite

2. Next step, just check if the module is currently active as part of the running Apache Webserver. Execute the following command to check it :

root@hostname:~# apachectl -M | grep rewrite
 rewrite_module (shared)

3. If there is no ‘rewrite’ module which in the active state as part of the running Apache Webserver, just run the following command :

root@hostname:/etc/apache2/mods-available# a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2

4. Finally, don’t forget to restart the Apache Webserver’s service as follows :

root@hostname:/etc/apache2/mods-available# systemctl restart apache2

One thought on “How to Activate mod_rewrite Apache Webserver Module in Linux Ubuntu 19.10 Operating System

Leave a Reply