3

We have a site currently with 1000s of pages with 10s of 1000s of urls linking internally to other pages. All current links use the "ugly" form of their url - ....com/?p=IDNUMBER.

In an SEO initiative, we're recreating the url structure. So, my question is, is it ok to leave the internal links "ugly?"

In Wordpress, will a link to ...com/?p=500 automatically redirect to its new pretty url, or will it be a broken link?

2

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!

1

The simple answer is "yes". Wordpress has a "canonical url" for each possible page and it will redirect to it if it was accesses from any other url. If you about page ID is "1" and the slug is "about", example.com/?p=1 will generate a request that wordpress will identify as being a request for the about page, but it will not serve the page for it but redirect to example.com/about first.

What is the canonical URL itself changes based on the permalink structure.

This said, I would still allocate some time to change the URLS in the content at some point, even for just an esthetic improvement, but also because relying on some internal "magic" number to identify content is just generally not a great idea and if for some reason you will need to restructure the DB (export with the wordpress exporter) the links will at best lead to nowhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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