Apache mod_rewrite is a very popular server module that, as per name, manage URL rewriting in a very flexible manner.
With the constant run around between server admins and developers (developers claiming : that’s the server, not the code – and the other way around for sysadmins : that’s the code, not the server); testing mod_rewrite in the first place for the sake of efficiency is a great idea, and here is how to do it.
1. Create a .htaccess file that contain :
RewriteEngine On RewriteRule ^.*$ mod_rewrite.php
2. Create a “mod_rewrite.php” at the root of the directory with the following content :
<?php echo "Mod_rewrite is activated!"; ?>
You should see a blank page with the message “Mod_rewrite is activated!” if successful.
Troubleshooting :
Hint 1 : If your .htaccess get ignored, this could potentially be caused by a <Directory> directive set to “AllowOverride None”. Make sure to set it to “AllowOverride All” so the .htaccess will be allowed/parsed by the server.
Hint 2 : If mod_rewrite isn’t actived on your LAMP server, enable it (a2enmod rewrite) and restart Apache (systemctl restart apache2). Running the command to enable it will tell if it was enabled or not, so there is no harm running it in any cases.