Redirect problem after migrating wordpress from root to subdirectory (2 posts)

  1. latrobe
    Posted 4 years ago #

    I migrated my wordpress blog from my root domain (example.com) to a subdirectory (example.com/blog/). Everything seems to be working fine, so I wanted to setup an .htaccess redirect at the root so that anyone who had bookmarked a specific post at the old URL (example.com/example-post-name/) will be directed to the new URL (example.com/blog/example-post-name/) instead of getting a 404 error.

    The wrench in this whole thing is that I want to still have a basic (non wordpress) page at the old root address, and I can't seem to figure out how to write a regular expression for the .htaccess file that forwards all the old posts, but ignores requests to go to the root.

    Here is what I am working with in the .htaccess file:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} example.com$ [NC]
    RewriteCond %{HTTP_HOST} !blog
    RewriteRule ^(.*)$ http://example.com/blog/$1 [R=301,L]

    This works great to redirect all the old posts to the new location, however when you type in http://example.com it directs to http://example.com/blog/, as you would expect. I am trying to figure out a way to write an exclusion of some sort that ignores requests to go specifically to example.com only.

    I've been banging my head against a wall for a while because this regular expression stuff is over my head, but I have a feeling that this might be pretty straight forward for someone who does this often. Any ideas?

  2. jpcutler85
    Posted 3 years ago #

    I don't have a solution, but I am looking for this answer as well. Did you manage to figure it out?

Topic Closed

This topic has been closed to new replies.

About this Topic