Website Migration-004 WordPress Debugging

After successfully migrating my WordPress site and restarting Apache, I encountered an issue where visiting any post or category (e.g., https://www.ruianding.com/blog/category/azureadtopics/aad-general/) returned a 404 error.

1. Identifying the Issue

The root cause seemed to be related to URL rewriting, which WordPress typically manages using the .htaccess file. Upon inspecting the directory, I realized that the .htaccess file was missing:

ls -la /data/ruianding.com/blog/.htaccess

2. Regenerating the .htaccess File

I attempted to regenerate the .htaccess rules via the WordPress Settings > Permalinks section. After saving the permalink settings and restarting Apache, the issue still persisted.

3. Fixing the Permissions

Upon further investigation, I discovered that WordPress did not have sufficient permissions to write to the .htaccess file. To resolve this, I adjusted the ownership of the WordPress directory to allow Apache to manage the files:

sudo chown -R www-data:www-data /data/ruianding.com/blog/

Previously, the WordPress website directory might have been owned by root or another user. If files were uploaded or extracted using root privileges, they would default to being owned by root. This command changes the ownership of the WordPress directory and its sub-files to www-data, which is the default user for Apache. This ensures that Apache has the necessary permissions to read, write, and manage files, allowing WordPress to execute background tasks (like generating the .htaccess file) successfully.


After fixing the file permissions, WordPress was able to generate the .htaccess file correctly, resolving the 404 errors on posts and categories. This step finalized the migration process, with all key components—Apache, MySQL, and WordPress—working smoothly on the Linux server.

With this, my entire website and blog migration from Windows to Linux is now complete 🎊!