Drupal Needs Mod_Rewrite in Apache2

This one was a real PITA!

When I got Drupal installed anything beyond the home page threw a ‘404’ error. The reason being is that Drupal needs clean URLs enabling and Debian / Apache2 default hasn’t got it enabled. Much reading and experimenting found this process to work:

  1. Add Options All after the

    <IfModule mod_rewrite.c>
    RewriteEngine on

    section

  2. Uncomment the line # RewriteBase /
  3. Insert the following before the last </IfModule tag>

    # Rewrite old-style URLS of the form 'node.php?id=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^id=([^&]+)$
    RewriteRule node.php index.php?q=node/view/%1 [L]

    # Rewrite old-style URLs of the form 'module.php?mod=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
    RewriteRule module.php index.php?q=%1 [L]

    # Rewrite URLs of the form 'index.php?q=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Reference: https://www.drupal.org/node/43783