Reputation: 505
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"
Upvotes: 0
Views: 87
Reputation: 1743
You could run the following command on the database:
UPDATE `wdp_posts`
SET `post_name`= REPLACE(`post_name`,"-and-","-"),
WHERE `post_date` < "20120101 00:00:00";
(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.
Upvotes: 1
Reputation: 36947
Theres options in Wordpress itself, to change the method of how the URLs are formed, I think its under the general options or maybe "writing". In either event you can customize whats used for the URL or use a predefined one. Wordpress is already utilizing htaccess
and mod_rewrite
for its needs to pass everything to the index.php. To alter that behavior and override what Wordpress needs may cause WP as a whole to break.
Bottom line, is there is methods for what you want to do.. they may fall under Wordpress Hacks, or they may be integrated options now in WP (its been a little while since I've used WP so I don't remember full well. But I know what your looking for in general is possible through WP directly...
To further on that, if your exporting from an old WP site to a new WP site, theres methods of exporting everything from posts to settings.. may want to consider that option as well.
Upvotes: 0