I am creating a new wordpress site. I’ve imported over 1500 of my posts from my old site. The problem is that wordpress has words like “an-the-a-if-is” in the URL, where my old website removed those.
This is a major problem for SEO and broken links as the new link looks like “the-cat-in-the-hat” and my old one just was “cat-hat”.
I want to ONLY change the past 1500 posts I’ve uploaded to strip specified words from the URL (via rewrite I assume), I have the list of words to remove. I want all new posts created to include the words, so I don’t just want to use .htaccess.
Is there a way via PHP to say “if post is older than XYZ date, strip these words, and serve it from the new rewritten URL, otherwise, serve it normally”
You could run the following command on the database:
(BACKUP THE DATABASE BEFORE YOU TRY THIS!)
What this does is rename any post from before the 1st of Jan 2011, removing any occurrences of “-and” in the name (which becomes the URL).
You’ll need to edit the date to fit your needs.
And you’ll need to run this multiple times. Once for “-and-“, once for “-if-“, once for “-in-” etc. As pointed out in a comment, it will not replace words at the start or end of the url.
You can do this in one query, but it’s rather hard to read so I’d recommend doing it one keyword at a time.