How To Reset WordPress Permalinks Using WP-CLI

You are here:
< All Topics

When transferring a WordPress website from one location or domain to another, or changing from https: to http: your permalinks will probably stop working.

 

The standard solution for this from WordPress.org is to resave your permalinks as type: plain in the WordPress Admin Dashboard.

 

However, if you are transferring or replicating your website and databases non-manually, ie automatically using a shell script, then you may want to perform this action using the WP-CLI or WordPress WP Command Line Interface tool.

 

 

Here are the instructions for changing your permalinks using WP.

 

You need to install WP-CLI on your WordPress server first in order to use this method.

 

 

if your permalinks are set to plain, then you get this output:

 

 

root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root

 

if they are set to postname, then you get this output:

 

root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root

/%postname%/
root@asus:~#

 

so, you need to set the structure to nothing:

 

 

root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root
/%postname%/
root@asus:~# wp option update permalink_structure ” ” –path=/var/www/wordpress –allow-root
Success: Updated ‘permalink_structure’ option.
root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root

root@asus:~#

 

Note the result of 

 

wp option get permalink_structure

 

is now a blank line. This means that the permalinks have now been set to ” ” ie plain format.

 

So you need to add ” ” as the argument for the value in order to set the permalinks to plain.

 

I checked in wp dashboard – settings – permalinks

 

– and this is correct.

Table of Contents