Here is a scenario for the issue:
1. XAMPP installed and configured. Apache web page is opening on http://localhost (default port 80)
2. Sites have been developed and placed under /htdocs including say, Drupal and WordPress sites.
3. Drupal and WordPress sites are working fine, and can be accessed on http://localhost/sitename
Now, suppose I needed IIS on the same machine for ASP developments. IIS is installed and it takes over the HTTP port 80. Or even Skype for that matter. Then the Apache HTTP port is changed.
4. Apache HTTP listen port is changed from 80 to 8080 in Apache's httpd.conf file. (See here: How to run Apache and IIS on the same computer)
5. Checked Apache service is starting with no issues using 8080 in the XAMPP Control Panel and the Apache default page opens, now at http://localhost:8080
6. Tested each site one by one - whether they are accessible using the new port 8080.
In my case, all other sites including Drupal sites, seems to embrace the port change well. They can be opened on the new port 8080 by accessing from the URL http://localhost:8080/sitename but not WordPress sites. After the port change, accessing WordPress sites using the url http://localhost:8080/sitename redirects to http://localhost/sitename. The browser returns HTTP 404 (Not found) error.
How to make WordPress sites work after changing Apache's HTTP port?
I haven't really dug in to see why WordPress will not work after the port change, but since the WordPress sites were working fine on port 80, but not on the new port 8080, I apply the same steps like I do when moving WordPress sites from local development having port 8080 to live server, that is, localhost URL edits.
The below steps are also required when moving WordPress site from local machine to live server, if local machine is using port 8080 for Apache.
1. Access phpMyAdmin: http://localhost:8080/phpmyadmin. Log in.
2. Click on the particular WordPress site's database.
3. Export it as SQL
4. Open the exported SQL file in a note editor (such as Notepad ++)
5. Do a Find & Replace:
Find = localhost
Replace = localhost:8080
6. Replace All
7. Save as: Save the file as a new SQL file
8. Back in phpMyAdmin:
phpMyAdmin > structure > select all the tables and drop
[If the edited SQL backup taken earlier is imported without dropping the tables, we get duplicate primary key error due to existing content.]
9. Import the edited SQL backup file
10. Check the WordPress site is accessible from the url http://localhost:8080/sitename
The WordPress site should now be accessible.