0

I am using wp-cli to create a WordPress website. I am running LAMP server. I am able to change the permalinks from ugly to pretty with the following commands:

wp rewrite structure '/%postname%'
wp rewrite flush

However, when I visit the website and click on the post, the permalinks are changed but it gives 404 not found. Is there a way to refresh the permalinks without going to wp-dashboard and click "Save" on the permalinks?

1
  • I found out the problem was that .htaccess file was not regenerated. It can be done using the wp rewrite flush --hard command and setting mod rewirte in wp-cli config.yml.
    – Badan
    Dec 13, 2023 at 18:27

1 Answer 1

0

I solved the problem by adding wp rewrite flush --hard command and setting mod rewirte in the global wp-cli configuration file:

wp rewrite structure '/%postname%/'
wp rewrite flush --hard

config.yml

apache_modules:
  - mod_rewrite

In this way, the .htaccess file gets regenerated. According to the official docs, this is needed in order to flush the permalinks.

I also wrote a detailed guide on how to update the permalinks on Apache web server with wp-cli: How to Update WordPress Permalinks with WP-CLI on LAMP Server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.