Before you do anything go to setting and tab Permalinks. Change this from Default to Post name.
To include the category, you select “Custom Structure” and change the value to /%category%/%postname%/
.
If you previously had ?p=<postid>
as your permalink WordPress will take care of all the redirects for you. This is also true if you change from /%postname%/
to /%category%/%postname%/
.
If you change from any other permalink structure save your changes of else changes won’t be saved.