Changing the permalink structure is definitely a big deal for an existing site. In order to test the various ways in which changing the permalink structure could break the site, I definitely recommend setting up a test environment.
So, my question is, is it ok to leave the internal links “ugly?”
I’m not sure from an SEO perspective if leaving the urls ugly would matter. It would be tedious, but if you have ssh
access, you can use wp-cli to search and replace the urls in the database:
wp search-replace 'example.com?p=123' 'example.com/post-slug'
You could also create a bash script to do that for each url.
In WordPress, will a link to …com/?p=500 automatically redirect to its new pretty url, or will it be a broken link?
The links will not be broken. From a technical standpoint, WordPress performs a 302
redirect.
So yes, the site will still ‘work’, but you indicate that this is in conjunction with an SEO initiative.
SEO things have more to do with the various indexes that search engines (Google, Bing, etc) have of your site. Note that a 302
redirect implies that the link has “Moved Temporarily”. Since you want to move all of the existing SEO “juice” from the old url to the new url, you need to tell the search engines that “This content exists, and has permanently moved”. For this you want to use a 301
redirect.
There are a couple of ways to do this.
WordPress Plugins
There are a few redirection plugins out there that I like:
But feel free to search and explore. The main drawback is that you have so many urls to input, and doing so for each url will probably be tedious.
Redirects at the Server Level
You can also create 301
redirects at the server level.
If you are running apache, then you can use its mod_rewrite engine inside of an .htaccess
file.
Nginx has it’s own rewrite module. I think that this blog post is a little easier to digest than the docs.
Getting a List of the URLs
In any case, one of the challenges is usually getting a complete list of posts, their ids, and the associated slug.
Since the current permalink structure includes the post ID, and the new permalink structure contains the post slug, getting a list of ‘before and after’ is pretty easy using wp-cli
. I’ve used this before to generate the post list:
wp post list --fields=ID,post_name --format=csv > posts.csv
This will give us a file called posts.csv
filled with the post id and slug of all the posts:
488,a-new-post-slug
495,another-new-post-slug
504,so-many-post-slugs
# ...
From there you can do batch transforms using Vim, Sed, or even a spreadsheet program since it’s a csv.
Hope this helps with your planing and execution!