Enable mod_rewrite in Apache

I have been posting hacklog.in blog articles on Facebook for some time. The URLs do not look nice when the address finish with something like ?p=858. A web link such as https://hacklog.mu/enable-mod_rewrite-in-apache is more readable than https://hacklog.mu/?p=858. To get a human readable link you need to change the permalinks settings in WordPress. Just go to Settings > Permalinks and select the format you want to use. Apart from the default all other formats require mod_rewite to be enabled. The latter isn’t enabled by default in openSUSE.

To enable mod_rewite you need to edit the Apache config file.

vi /etc/sysconfig/apache2  

Search for the line containing APACHE_MODULES.

APACHE_MODULES=”actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime rewrite negotiation setenvif ssl userdir php5 reqtimeout deflate authnz_ldap ldap wsgi”  

Add rewrite to the APACHE_MODULES list and restart apache.

systemctl restart apache  

Make sure you have the directive AllowOverride All set in your apache/vhost conf. WordPress already has RewriteEngine enabled in your site’s .htaccess file. Here’s a sample setting :

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

Share this post