To fix this:
Go to WordPress Dashboard → Settings → Permalinks. Select the "Post name" option (/sample-post/). Click Save Changes. If you still get 404 errors, try the following:
Flush Permalinks: Just re-saving the permalinks in Settings can fix the issue. Check .htaccess (if on Apache): If you're using an Apache server, WordPress needs to write to the .htaccess file. Make sure it has the correct rewrite rules. Check Hosting Settings: Some hosts may override permalinks with default settings.