“The requested URL /projectname/pagename/ was not found on this server.” issue on WordPress website

Solution:

Turns out that .htaccess was not the issue for me. The issue was in server configuration file. Posting my answer in case any one bumps into similar issue and looking for a solution.

For AWS EC2 server:

Step 1: Edit configuration file

sudo nano /etc/httpd/conf/httpd.conf

Edit this file and change

<Directory /var/www/html/wordpress/>
    AllowOverride None
 </Directory>

to

<Directory /var/www/html/wordpress/>
    AllowOverride All
 </Directory>

Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.

Step 2: Restart server

Please don’t forget to restart your server after you do the changes to the .conf file.

sudo service httpd restart

For Ubuntu server:

Step 1: Edit configuration file

sudo gedit /etc/apache2/apache2.conf

Edit this file and change

<Directory /var/www/html/wordpress/>
    AllowOverride None
 </Directory>

to

<Directory /var/www/html/wordpress/>
    AllowOverride All
 </Directory>

Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.

Step 2: Restart server

Please don’t forget to restart your server after you do the changes to the .conf file.

sudo service apache2 restart