How to publish new posts/pages in root instead of subfolder, but keep old structure in place?

I have a blog that was setup in example.org/blog/ many years ago, so all its files are in /blog/. Back then it seemed like a good idea, but now we want to slowly get rid of the subfolder.

Of course I could move the installation to the root folder /, change the wordpress url in option and just move everything, add a htaccess redirect from /blog/* to /* so old links still work.

Read More

But we want to do it slowly because moving all the content at once would be a major risk and possible desaster for the Google rankings and traffic. 301/302 redirects are fine, but Google is not very happy if you move thousands of articles at once while the links stay the same. So new content first, then old stuff.

Is there any way to only publish new posts and pages in example.org/ instead of example.org/blog/?

I’m capable of all kinds of hacks. I already have several blogs running with the WordPress installation in subfolders, have redirected and moved blogs all over the place and written scripts to change the values of all rows in a database table. Bring it on 🙂

Related posts

2 comments

  1. Mmmm, I think that if you are thinking on a major change for the project, you could proceed as follow:

    1. Of course, create a development snapshot of your site, somewhere else. Fork files and database, You can even fool the development vhost and the developer client so you dont even need to change the url-related parameters in the wp_options table of the database.
    2. In the database, replace every pattern of “http://mydomain.tld/blog/” for “http://mydomain.tld/“. Keep in mind that you may have a few variations of this pattern (with/without www, with/without https, etc.).
    3. After performing those tasks, you could move all the files and set a single Redirect rule to move the whole blog, with updated intra-links fitting the new url pattern and therefore not annoying google 🙂

    If your site is showing the counting of “social shares” to the visitor for any URL, that would definitely be an issue. But it is already solved and mimicking the approach recommended at Encosia should be enough if this is an issue for your project.

  2. I think the best way, is that you change globaly, also the old post, remove the subfolder.

    But I think it is also possible that you use the hook publish_post / _page to change the rewrite rules for new posts/pages. Maybe you can learn on Toschos examples source to understand the rewrite possibilities, see his repo on github. But this generate also a performance topic. The logic must check on, if the post new, since date mm.yyyy and change ad hoc the permalink. Much more complex as a change globaly. Maybe it is better, that you enhance the old posts with a rewrite, that all posts also works from the old /blog/ url.

Comments are closed.