I encountered this problem when I tried to set up a drupal site from an existing codes given to me. Firstly, I successfully imported database from the dump file given. Then copy the drupal base code to document root subdirectory at /var/www/my-site-name. I also modified the sites/default/settings.php to reflect the new base url and new database. Here are the modifications you need to do:
$base_url = ‘http://localhost/my-site-name‘;
and
$db_url = ‘mysqli://database-username:database-password@localhost/database-name‘;
Of course, you need to replace the italic texts with your own names.
So the database settings was fine and I could go to the homepage. However, whatever links I clicked from the homepage the 404 Not Found error came out. What was wrong? After some research, I discovered that the clean URL did not work on my apache and drupal. What “clean URL” does is to map query strings to a “flat” URLs. For example, http://localhost/drupal?q=user will be mapped to http://localhost/drupal/user. Following some online instructions, I realized that the .htaccess file which goes with drupal installation was missing. I copied the default .htaccess to the site folder and made necessary changes to enable Rerwrite mode on apache. Here is what segment you need in .htaccess:
RewriteEngine on
RewriteBase /my-site-name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I tried again, but the links still did not work. What turned out to be missing is the apache configuration, in particular the settings in /etc/apache2/sites-available/default file. The original file looks like this:
………………………………..
………………………………..
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
………………………..
……………………….
All you need to do is to change from
AllowOverride None
to:
AllowOverride All
Now at command line, run:
sudo a2enmod rewrite
and then restart apache:
/etc/apache2/init.d/restart
That’s it.