Redirect problem after migrating wordpress from root to subdirectory
-
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 ^(.*)$ https://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 https://example.com it directs to https://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?
- The topic ‘Redirect problem after migrating wordpress from root to subdirectory’ is closed to new replies.